How to pre-select an option from a drop-down box?

Oct 19, 2000
17,860
4
81
I have a drop-down box on my web-page where a user selects a refresh rate. This is stored in a cookie once the user submits his settings. What I'd like to do is when that user comes back to the settings screen, his default rate is automatically selected in the drop-down box instead of whatever is first in the list.

I know how to do this for other things, but doing this for a drop-down box has eluded me. I've googled a bit on the subject, and it seems as if you have to use javascript to do this. Can anyone help me out on how to implement this?
 

GeekDrew

Diamond Member
Jun 7, 2000
9,099
19
81
What kind of language are you using for this website? PHP?

The short version of what you'll need to do is output the select box's HTML item with the "selected" parameter set. For example:

<option selected="selected" value="1000">11tyB Hz</option>

That'll make it the default in the drop-down box.
 
Oct 19, 2000
17,860
4
81
Yes, I'm using PHP. In all my searching, I never saw the "selected="selected"" part. I knew of "checked" for radio buttons and the like, but never saw this. I'll give that a shot and see what happens, thanks.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0

<option value='whatever' SELECTED>

do you know how to make the php to check for the cookie and output the 'selected'?
 
Oct 19, 2000
17,860
4
81
Originally posted by: troytime

<option value='whatever' SELECTED>

do you know how to make the php to check for the cookie and output the 'selected'?

Yep, got it working yesterday, thanks. :)