Page 1 of 1

Setting Default Value of Select - Option Tag in PHP

Posted: Sat Mar 06, 2010 6:16 pm
by devarishi
Let's suppose Support Group has the value (in the database) "Help Desk" (it could be any other value also) and on this web page which is meant for chaning the value (if required so), the original value should be selected by default:

Code: Select all

Support Group   <select name="supportGroup" value= <?php echo '"' . $rs->Fields['supportGroup']->Value . '"'; ?> >
    <option value="Backup"> Backup </option>
                                        <option value="DBA Support"> DBA Support  </option>
                                        <option value="Help Desk"> Help Desk </option>
</select>   
However, it displays the first option value, i.e. "Backup".

Any ideas?

Re: Setting Default Value of Select - Option Tag in PHP

Posted: Sat Mar 06, 2010 6:24 pm
by requinix
Basic HTML knowledge.

Code: Select all

<option value="Help Desk" selected="selected"> Help Desk </option>

Re: Setting Default Value of Select - Option Tag in PHP

Posted: Sat Mar 06, 2010 8:36 pm
by devarishi
tasairis wrote:Basic HTML knowledge.

Code: Select all

<option value="Help Desk" selected="selected"> Help Desk </option>


Hi,

That is okay. But the value of the option element is coming from a database (table).

Code: Select all

<?php echo '"' . $rs->Fields['supportGroup']->Value . '"'; ?>
Whatever value is there, it has to be displayed in the Drop-Down-Menu by default. The purpose is to enable the user change its value if he/she wants to. Otherwise leave it as it is. And in the later case, the original value must be displayed so that when the Select Element is referred in another web page we get a value depending upon whether it was changed or not.

Note: There are several other text elements on the same page and all of them are editable so that one can change their values if required. Otherwise, their original values are passed to the next web page for processing (updating).

Re: Setting Default Value of Select - Option Tag in PHP

Posted: Sat Mar 06, 2010 8:52 pm
by requinix
Okay. So only output the selected="selected" if it's supposed to be.

Hint: if.