Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled option in Firefox bug

I was creating some form when I saw that in Firefox. In a select box, if you add a disabled option as first choice... it select the next available option

<option disabled="disabled" value="false">Choose option</option>
<option value="1">Value 1</option>

It will select "Value 1" when the page is loaded.

Why every browser will select the disabled one by default and Firefox not?

Load this in Firefox : http://jsfiddle.net/6WjgZ/1/

and other browser you'll notice that Firefox bypass the disabled one and select the "Value 1" by default.

like image 647
Warface Avatar asked Aug 01 '11 19:08

Warface


1 Answers

Assuming you want a workaround, run this code on DOM Load (or body load) to fix it in Firefox

document.getElementById("mySel").selectedIndex = 0;

http://jsfiddle.net/6WjgZ/2/

Not sure if this can be called a bug (more of a behavior style), if you think about it, FF doesn't let you choose disabled items. Neither does other browsers (except IE) but then, they choose to behave differently for the initial load.

like image 178
Mrchief Avatar answered Nov 16 '22 04:11

Mrchief