Jump to content

value in value php form


bishop2001

Recommended Posts

You get the selected value from $_GET or $_POST (depending on your forms submit method), example code

<?php

if(isset($_POST['day']))
{
   echo 'You selected: ' . $_POST['day'];
}

$days = ('Monday', 'Tuesday', 'Wednesday', 'etc...');
?>
<form action="" method="post">
<select name="day">
<?php foreaach($days as $today) {
   <option><?php echo $today ?></option>
<?php } ?>
</select>
<input type="submit" value="Go" />
</form>

Note that there are a few errors in Ch0cu3r's code. It should look more like the following:

<?php
if(isset($_POST['day']))
{
   echo 'You selected: ' . $_POST['day'];
}
 
$days = array('Monday', 'Tuesday', 'Wednesday', 'etc...');
?>
<form action="" method="post">
<select name="day">
<?php
foreach($days as $today) {
    echo "<option>$today</option>";
}
?>
</select>
<input type="submit" value="Go" />
</form>

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.