Uros K
Uros K

Reputation: 3384

Select box with empty option, which is not present in html dom

At this website: http://www.salus.si/en (if you click on "change" in top banner*) the select element starts with an empty option. HTML looks like this:

<select id="cc-preference-selector-analytics">
    <option value="yes">I accept</option>
    <option value="no">I do not accept</option>
</select>

Here is the same select element in jsfiddle: http://www.jsfiddle.net/JG89n - which shows the first option. Why is this happening?

Thanks.

**If you have "Send do not track headers" enabled in your browser, you wont see the banner. Its a cookie consent banner which doesn't get displayed if user has this feature enabled. IE10 has it enabled by default. Banner looks like this (top of the page): Site screenshot*

Upvotes: 1

Views: 395

Answers (1)

Siva Charan
Siva Charan

Reputation: 18064

You haven't set the default option, so it displays empty.

If you want default selection as "I accept", do this way:-

<select id="cc-preference-selector-analytics">
    <option value="yes" selected="selected">I accept</option>
    <option value="no">I do not accept</option>
</select> 

Update:

Mostly like, this is a browser behaviour and also I think your javascript can also cause this issue.

Upvotes: 1

Related Questions