Johnny
Johnny

Reputation: 9974

jquery .change() in firefox

I'm using the jQuery change to change the values of another select drop down whenever the user changes the month (so that the right number of days is displayed). This works great in all browsers except Firefox :(

Suffice to say the code is a big like this

$(document).ready(function() {

var leap;

$('.dob').change(function() {

var y = $('#ryear option:selected').html(); /* The year selected */
var s = $('#rmonth option:selected').html(); /* The month selected */

});


});

Then I alter the data with the variable values in mind. There are 3 selects with .dob, so its a bit like this

<select class="dob" id="rday">
     <option id="01">01</option>
     ....
</select>
<select class="dob" id="rmonth">
     <option id="1876">Jan</option>
     ....
</select>
<select class="dob" id="ryear">
     <option id="1876">1876</option>
     ....
</select>

In firefox when I select the month or year select drop down (the value of the day isnt really selected by the script so it isnt affected), well, the drop down flashes and appears, and then instantly disappears on a single click in Firefox.

Any ideas why the script is doing this?

Upvotes: 0

Views: 1442

Answers (3)

Ilia Draznin
Ilia Draznin

Reputation: 1046

I would recommend rewriting the code first to be standards compliant, which means replacing IDs with values, i.e. <option value="1876"> (BTW IDs, as pointed out, can't start with a digit http://www.w3schools.com/tags/att_standard_id.asp)

Also, when you're getting the value use .val(), so

var y = $('#ryear option:selected').val();

With those fixes see if you still get the problem.

Also, it occurs to me that if your select handing function "forces" value selection in another select box, which also has the same select handler, there could be interference of some sort. I would recommend, at least for testing purposes, to assign unique id to each select and create unique functions for each.

Upvotes: 0

epascarello
epascarello

Reputation: 207537

ids can not start with numbers.

ids have to be UNIQUE identifiers.

Upvotes: 1

Shishant
Shishant

Reputation: 9294

I believe it is to do with data type, Instead of var y = $('#ryear option:selected').html();

try this var y = $('#ryear option:selected').val(); ||
var y = $('#ryear option:selected').attr('id'); ||
parseInt(y);

Upvotes: 0

Related Questions