Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Auto Filling Form Data ... specifically a select drop menu

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Auto Filling Form Data ... specifically a select drop menu

Postby meannate » Mon Nov 04, 2002 12:26 pm

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
meannate
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Nov 04, 2002 12:06 pm
Location: West Los Angeles

Postby DoppyNL » Mon Nov 04, 2002 12:32 pm

add "selected" to the item you want selected:
Code: Select all
<option name="IveGotAName" value="whatever" selected>blablabla</option>


Greetz Daan
DoppyNL
 

Postby meannate » Mon Nov 04, 2002 12:36 pm

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?
meannate
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Nov 04, 2002 12:06 pm
Location: West Los Angeles

Postby Jay » Mon Nov 04, 2002 12:39 pm

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).
Jay
 

hmmmmmm...

Postby meannate » Mon Nov 04, 2002 12:50 pm

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
meannate
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Nov 04, 2002 12:06 pm
Location: West Los Angeles

Postby Jay » Mon Nov 04, 2002 12:53 pm

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>";
Jay
 

Postby meannate » Mon Nov 04, 2002 12:55 pm

Jay:

I think that's the way... I'm retarded... thanks dude!

-Nathan
meannate
New php-forum User
New php-forum User
 
Posts: 8
Joined: Mon Nov 04, 2002 12:06 pm
Location: West Los Angeles


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron