View Full Version : How to select the first value in the drop down as the default value

11-12-2008, 06:38 PM
Hi Guys,
I need some help in retreiving the first value in the dropdown list as the default value. The values are retrieved from the Oracle database through the SQl queries. the JS code for that drop down is as follows,

td.innerHTML = '<select class="formEntryField" name="_' + cr + 'aProbTypeT2' + rc + '" onChange="javascript:document.frmEntry.__' + cr + '.checked = true;" >' + probT2Codes + '<option value="" selected = "selected">* - Not Identified </option> </select>';

The above query sets the default value as * - Not Identified...but I need that default value to be the first value I get from the database.

Thanks in advance,

11-12-2008, 09:14 PM
You really haven't given us much to go on. Of particular interest would be how the rest of the options in the select are created. Just going from what you have shown, I'd say just skip:

<option value="" selected = "selected">* - Not Identified </option>

That way (presumably), the first option will be the first one from the data base. The first option is always selected by default (at least in modern browsers). You could perhaps arrange though to have it bear the selected attribute. That is recommended, but in all likelihood would not be required.

This really sounds more like a server side issue, though it does look like you are combining that with javascript. If javascript can be avoided, your page will be more accessible.