pamelaanne Posted February 26, 2012 Share Posted February 26, 2012 I'm doing this activity where a user chooses a base timezone and when the user clicks convert the current time in the selected GMT will be converted to GMT-11 to GMT+13. As of now, I have these codes: act09_view.php: <?php session_start(); $s="GMT "; echo "Select the base time zone:</br>"; for($n=-11;$n<=13;$n++) { if ($n>=0) $s="GMT +"; $gmt[]=$s . $n . "</br>"; } echo "<select name='gmt'>"; foreach ($gmt as $value) { echo '<option value="' . $value . '">' . $value . '</option>\n'; } echo '</select>'; //$_SESSION['value']=$value; ?> <form action="act09_process.php"> </br><input type='submit' value='Convert'/> </form> act09_process.php: <?php session_start(); //$value=$_SESSION['value']; //echo $value; date_default_timezone_set('Asia/Manila'); $gmttime=date('M j, Y g:i:s A'); echo "The current date and time at" . " is " . $gmttime; ?> I've tried using session variables. I think I executed them incorrectly. The output is supposed to look like this: Quote Link to comment https://forums.phpfreaks.com/topic/257812-how-to-retrieve-value-from-drop-down-list/ Share on other sites More sharing options...
Kieran Menor Posted February 26, 2012 Share Posted February 26, 2012 Drop-down lists are like any other form elements. Alike so: <form method="POST" action="posthandler.php"> <select name="gmt"><option value="...">...</option></select> <input type="submit" /> </form> and in posthandler.php: <?php echo $_POST['gmt']; ?> It seems that in your case, all you need to do is to move the <select> element inside your <form>, and possibly add action="POST" to the <form> also. Quote Link to comment https://forums.phpfreaks.com/topic/257812-how-to-retrieve-value-from-drop-down-list/#findComment-1321395 Share on other sites More sharing options...
AyKay47 Posted February 26, 2012 Share Posted February 26, 2012 It seems that in your case, all you need to do is to move the <select> element inside your <form>, and possibly add action="POST" to the <form> also. Err. method="post" Not action Quote Link to comment https://forums.phpfreaks.com/topic/257812-how-to-retrieve-value-from-drop-down-list/#findComment-1321435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.