Howdy-
I'm developing an online inventory database with a status field containing three "states" (new order / in progress / finished). This is done using a form <INPUT SELECT> field, as you might imagine. The problem I'm having is having the SELECT field reflect my user's choice after they hit the update button and the page reloads. I know I've done this in another language (AESTIVA) however it was a proprietary language and the theory doesn't translate. Anyone with information / ideas would be greatly appreciated!
-Nathan
Auto Filling Form Data ... specifically a select drop menu
Moderators: egami, macek, gesf
add "selected" to the item you want selected:
Greetz Daan
Code: Select all
<option name="IveGotAName" value="whatever" selected>blablabla</option>
Greetz Daan
-
- New php-forum User
- Posts: 8
- Joined: Mon Nov 04, 2002 12:06 pm
- Location: West Los Angeles
- Contact:
DoppyNL: Thanks for the reply! However I'm trying to dynamically select which field... like this:
The user comes to the page, selects the option they'd like from the drop-down menu... they hit the update button, my script updates the MySQL database with their option, and the page reloads... on the reload, I'd like the page to reflect the previously selected option... instead of selecting the default (top item)... any way to do this?
The user comes to the page, selects the option they'd like from the drop-down menu... they hit the update button, my script updates the MySQL database with their option, and the page reloads... on the reload, I'd like the page to reflect the previously selected option... instead of selecting the default (top item)... any way to do this?
Well, your server obviously knows what option was selected as it updates the database. When you're outputting the code (doesn't work if it's pre-written), but add a 'selected' to the option that was selected. You should be able to match them up pretty easily from the 'value' values (which should all be unique).
-
- New php-forum User
- Posts: 8
- Joined: Mon Nov 04, 2002 12:06 pm
- Location: West Los Angeles
- Contact:
Okay, so here's where I'm at now:
I'm forming the output table and trying to test the value of $job_status for each <OPTION> field... so before it's like this:
$display_block .= "<SELECT NAME=\"job_status\">OPTION VALUE=\"In Progress\">In Progress</OPTION><OPTION VALUE=\"Finished\">Finished</OPTION></SELECT>";
I want to add a way to check the value of $job_status and ECHO "SELECTED" in the right spot... ya know?
So, how do I add: IF ($job_status == "In Progress") echo "SELECTED"; without messing up my $display_block...
-confused
I'm forming the output table and trying to test the value of $job_status for each <OPTION> field... so before it's like this:
$display_block .= "<SELECT NAME=\"job_status\">OPTION VALUE=\"In Progress\">In Progress</OPTION><OPTION VALUE=\"Finished\">Finished</OPTION></SELECT>";
I want to add a way to check the value of $job_status and ECHO "SELECTED" in the right spot... ya know?
So, how do I add: IF ($job_status == "In Progress") echo "SELECTED"; without messing up my $display_block...
-confused
Errm, normally you'd use PHP to generate the options menu dynamically, rather than hard coding it. But if you want you can use this:
$selected = ($job_status == "In Progress")? "selected":"";
$display_block .= "<SELECT NAME=\"job_status\"><OPTION VALUE=\"In Progress\" $selected>In Progress</OPTION><OPTION VALUE=\"Finished\">Finished</OPTION></SELECT>";
$selected = ($job_status == "In Progress")? "selected":"";
$display_block .= "<SELECT NAME=\"job_status\"><OPTION VALUE=\"In Progress\" $selected>In Progress</OPTION><OPTION VALUE=\"Finished\">Finished</OPTION></SELECT>";