...

View Full Version : combo



bunny1
03-10-2007, 02:46 PM
I have a combo box :


<select name="stock" id="stock">
<option value="In Stock">In Stock</option>
<option value="Not in Stock">Not in Stock</option>
<option value="Discontinued">Discontinued</option>
</select>


I am connecting to the database and i want to display the results in a form and change the value of the combo box to the one value in the database for that record.

How would i set the combo box to the correct value using php.
Im not sure if this is a html or a php question

Inigoesdr
03-10-2007, 02:50 PM
Both actually, you just have to add "selected" inside of the option tag. You can use an if() switch or ternary operator to do it with, it's pretty straight-forward.

<option value="1"<?=!empty($selected) ? ' selected' : '';?>>Selection</option>

bunny1
03-10-2007, 03:10 PM
The problem i have is i dont know where i should do an if statement and how to construct it to check each option for it's value.
would i do it within the <option> tag or above the <select> tag and how do you refer to the html tags within php?

I havent a clue how to do this!

thanks

Inigoesdr
03-10-2007, 03:15 PM
I just showed you in my previous post. You have to make one for each option.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum