Page 1 of 1

How Can I Get The DropDown List value on Next Page ?

Posted: Tue Dec 06, 2005 1:56 pm
by saqib389
here is the code of

page1.php

Code: Select all

<html>
<head>
<title>My Page</title>
</head>
<body>
<form name="myform" action="display.php">
<div align="center">
<select name="mydropdown">
<option value="color1">black</option>
<option value="color2">red</option>
<option value="color3">Orange</option>
</select>
</div>
</form>
</body>
</html>
now i want to display on DISPLAY.PHP
the value of that which user selected in dropdownlist
like user select red option. then on next page there shuld b display RED and also there shuld b display RED COLOR.......
can any one tell me how can i dot this ?

Posted: Tue Dec 06, 2005 2:06 pm
by Deemo
AFAIK you can only get the values from the drop down menu. Meaning if the user selected red, $_POST['mydropdown'] would return color 2. I dont know if its possible to get the text as well, but usually only the value is important

Posted: Tue Dec 06, 2005 2:07 pm
by John Cartwright
on display.php

Code: Select all

//simplest way
//would fire error if mydropdown was not set
echo $_POST['mydropdown'];

//better way
echo (!empty($_POST['mydropdown']) ? $_POST['mydropdown'] : 'My Drop Down was not set');
If you actually want it to display RED, then your going to have to change your form

Code: Select all

<option value="black">black</option>
<option value="red">red</option>
<option value="orange">Orange</option>
or you can do something like

Code: Select all

$colors = array(
   'color1' => 'BLACK',
   'color2' => 'RED',
   'color3' => 'ORANGE'
);

//check if mydropdownmenu exists
$color = (!empty($_POST['mydropdownmenu']) ? $_POST['mydropdownmenu'] : 'color1');
//check if its an acceptable value
if (in_array($color, $colors))
   echo $colors[$color];
//if not display default
else
   echo $colors[1];

I suggest you take a read http://ca.php.net/variables.predefined

Posted: Tue Dec 06, 2005 4:21 pm
by saqib389
Thx... I gOT mY aNSWER..... clap for You :)