Jump to content

Select Menus


Mko

Recommended Posts

So I have the following code, which is supposed to get the value selected by the user, then on submitting, will use that value in the URL.

 

$durations = array("1", "2", "3", "4", "5", "7", "10", "10000000");

echo "Choose Duration: ";?><form method="post" action=""><select name="duration_chosen">
	<?
		foreach($durations as $duration){
			?><option name="duration_len" value="<?php echo $duration;?>"> <? 
			if ($duration == "10000000") {
				echo "Forever";
			} else {
				echo "$duration day(s)";
			}
			 ?></option><?
		}
	?>
	</select></form><?
$hrs = $_GET['duration_len'] * 24;
$duration_chosen = $_POST['duration_chosen'];
?>
<form method="get" action="index.php">
<input type="hidden" name="duration" value="<? echo $duration_chosen; ?>">
<input type="submit" value="Accept"></form>

 

For some reason, though, it doesn't work.

Can anyone help me?

 

Thanks,

Mark

Link to comment
https://forums.phpfreaks.com/topic/260392-select-menus/
Share on other sites

also you should use the full php tag rather than the short tag... from what i can see... you are trying to do something like this:

 

$durations = array("1", "2", "3", "4", "5", "7", "10", "10000000");

echo "Choose Duration: ";?><form method="get" action="index.php"><select name="duration_chosen">
	<?php
		foreach($durations as $duration){
			?><option name="duration" value="<?php echo $duration;?>"> <?php
			if ($duration == "10000000") {
				echo "Forever";
			} else {
				echo "$duration day(s)";
			}
			 ?></option><?php
		}
	?>
	</select>
                <input type="submit" value="Accept">
                </form>

 

and then you can process $_GET['duration'] on the page this form is getting sent to

Link to comment
https://forums.phpfreaks.com/topic/260392-select-menus/#findComment-1334604
Share on other sites

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.