• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

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?
 
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.
 
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.
 

<option value='whatever' SELECTED>

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