Search code examples
htmljqueryjquery-mobileradio-button

Selected Radio option using change() not working as expected with JQM (jQueryMobile)


I'm seeing a strange issue with Radios and the change() function using the JQM (jQueryMobile) lib.

When clicking the radio I get the previous value instead of the new value Shown here: http://jsfiddle.net/fSbk9/3/

but it should execute like this, shown here:
http://jsfiddle.net/N6qmr/10/
where the change() should show the selected value not the old value.

Any thoughts?

UPDATE:

Here is the working version: http://jsfiddle.net/fSbk9/15/


Solution

  • It is a very interesting behavior. The change function is called onclick by JQM, then you see the alert message and after clicking ok on the alert message you will see that the selected value of the radiobox will switch. So the function is called before the change was done, and so the value is wrong. But the reason why, hmm... I solved it:

    Do this:

    alert($('input[name=first_radio]:checked').val());
    

    See here: http://jsfiddle.net/fSbk9/6/