sparky-nyc
asked on
How to use selectedIndex value in a hidden field?
All I want to do is to pass the selectedIndex value in a hidden field at the end of my script. I'm assigning the selected value to $selvalue, which I know is receiving the selectedIndex value (which I can see with the alert window), but $selvalue seems to be in a local scope. In other words, if I try printing $selvalue at the end of the script, it shows up as empty!
Can someone please tell me what I'm missing? Thanks!
Here's sample code:
<?PHP
// filename: myscript.php
function choosecolor()
{
include "header.php"; //html header stuff
echo "<form name=\"form1\" action=\"myscript.php\" method=\"post\">\n";
echo "<select name=\"selbox\" onchange=\"\$selvalue = this.options[this.selected Index].val ue;alert(\ $selvalue) ;\" >";
echo " <option value=\"red\">Red</option> ";
echo " <option value=\"green\">Green</opt ion>";
echo " <option value=\"blue\">Blue</optio n>";
echo "</select>\n";
echo "<input type=\"hidden\" name=\"colorchoice\" value=\"$selvalue\">\n";
echo "<input type=\"submit\" value=\"next\">\n";
echo "</form>\n";
echo "\$selvalue = $selvalue\n"; // !!! is empty !!!
include "footer.php"; //html footer stuff
}
... // other functions
// end of file.
?>
Can someone please tell me what I'm missing? Thanks!
Here's sample code:
<?PHP
// filename: myscript.php
function choosecolor()
{
include "header.php"; //html header stuff
echo "<form name=\"form1\" action=\"myscript.php\" method=\"post\">\n";
echo "<select name=\"selbox\" onchange=\"\$selvalue = this.options[this.selected
echo " <option value=\"red\">Red</option>
echo " <option value=\"green\">Green</opt
echo " <option value=\"blue\">Blue</optio
echo "</select>\n";
echo "<input type=\"hidden\" name=\"colorchoice\" value=\"$selvalue\">\n";
echo "<input type=\"submit\" value=\"next\">\n";
echo "</form>\n";
echo "\$selvalue = $selvalue\n"; // !!! is empty !!!
include "footer.php"; //html footer stuff
}
... // other functions
// end of file.
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: pickett_richard {http:#8223044}
Any objections should be posted here in the next 4 days. After that time, the question will be closed.
snoyes_jw
EE Cleanup Volunteer