Jump to content

How to retrieve value from drop-down list?


pamelaanne

Recommended Posts

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.  :confused:

 

The output is supposed to look like this:

21l72j9.png

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.