Page 1 of 1

Need help with drop down list

Posted: Fri Oct 07, 2005 2:21 am
by vigour
I want this code to call process.php when I select something in the drop down list. How can I do this?

Code: Select all

echo '<html>';
echo '<body>';
echo '<form action="process.php" method="post">';
echo '<select name="item">';
echo '<option>1</option>';
echo '<option>2</option>';
echo '<option>3</option>';
echo '</select>';
echo '</form>';
echo '</body>';
echo '</html>';

Posted: Fri Oct 07, 2005 3:26 am
by n00b Saibot

Code: Select all

echo '<select name="item" onchange="this.form.submit()">';
you are better off outputting static HTML outside PHP instead of using PHP to output HTML.

Posted: Fri Oct 07, 2005 3:35 am
by vigour
Thanks, that worked. Is there a way to set a drop down list to a value with PHP? For example, I have 3 values in the drop down list, 1 2 3, and I want to set it to any of these values with PHP.
n00b Saibot wrote:

Code: Select all

echo '<select name="item" onchange="this.form.submit()">';
you are better off outputting static HTML outside PHP instead of using PHP to output HTML.

Posted: Fri Oct 07, 2005 3:46 am
by n00b Saibot
Lets says $item stores the selection. then

Code: Select all

echo "<option ".($item==1?' selected':'').">1</option>";
likewise others.