0

I realized this issue has already been discussed that Firefox doesn't accept the option as selected. But all the existing workaround I have found only works during page loading. But my code is setting up the selected option dynamically in the page. Here is my piece of code:

$('.RemoveSelect').click(function(e) {

            //..
            if (slimit <= 2) {
                $('#duration').attr('disabled', 'disabled');
                $('#oneTurnPerPerson').attr('selected', 'true');
            }
}

This works well for chrome but doesn't work for FF at all. Is there any workaround for this?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Lance Shi
  • 1,127
  • 3
  • 13
  • 28
  • `.attr('selected', 'true');` should be `.attr('selected', true);` or try `prop`? Or this http://stackoverflow.com/a/10096033/3639582 – Shaunak D May 05 '15 at 04:39
  • If the elements are being loaded dynamically, you need to use event delegation: http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Barmar May 05 '15 at 04:42
  • @ShaunakD Thank you for your suggestions. But I don't think this issue is related to attribute. Those elements are there when page loads, but I need to change the attr dynamically. And the attr gets changed. The issue with that is FF doesn't take selected option as default display. Related: http://stackoverflow.com/questions/4831848/firefox-ignores-option-selected-selected?lq=1 – Lance Shi May 05 '15 at 05:02

1 Answers1

0

The disabled and selected are boolean attributes.

The correct way to write is:

$('.RemoveSelect').click(function(e) {

            //..
            if (slimit <= 2) {
                $('#duration').attr('disabled', true);
                $('#oneTurnPerPerson').attr('selected', true);
            }
}
Brijesh Bhatt
  • 3,810
  • 3
  • 18
  • 34
  • Thank you for your suggestion. But this doesn't make a difference. In the developer tool of FF you can find that your code will be translated into disabled="disabled" and selected="selected" anyway. Linked question: http://stackoverflow.com/questions/4831848/firefox-ignores-option-selected-selected?lq=1 – Lance Shi May 05 '15 at 04:58