Need help with drop down list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vigour
Forum Newbie
Posts: 18
Joined: Thu Sep 29, 2005 2:04 am

Need help with drop down list

Post 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>';
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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.
vigour
Forum Newbie
Posts: 18
Joined: Thu Sep 29, 2005 2:04 am

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Lets says $item stores the selection. then

Code: Select all

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