Software Archive
Read-only legacy content
17060 Discussions

jQuery Mobile - Radiobox Change Doesn't work

Fatih_Mert_D_
Beginner
814 Views

Hi guys,

I am still learning and working on Intel XDK platform.

I was switch multipage applications trials.

My project in has two pages, These are  #mainpage and #settings

Main page in click settings button go to the #settings page. This page has radiobox language switch button.

<fieldset data-role="controlgroup" data-type="horizontal">
    <legend>Select Your Language:</legend>
    <input name="selectLang" id="radio-choice-h-2a" value="en" checked="checked" type="radio">
    <label for="radio-choice-h-2a">English</label>
    <input name="selectLang" id="radio-choice-h-2b" value="ru" type="radio">
    <label for="radio-choice-h-2b">Russian</label>
</fieldset>

And I am controlling in app.js follow here;

window.currentLanguage = "en";

$(document).ready(function(){
    
    //Language Init
    if(window.currentLanguage == "en"){
        $('input[name=selectLang][value=en]').attr("checked",true);
        $('input[name=selectLang][value=ru]').attr("checked",false);
    }else{
        $('input[name=selectLang][value=en]').attr("checked",false);
        $('input[name=selectLang][value=ru]').attr("checked",true);
    }

    //It is working
    alert($('[name="selectLang"]').val());

    //It is not working
    $('[name="selectLang"]').click(function(){
        alert($(this).val());
    });
    
});

I don't understand. Where is the problem? I had try .on and .delegate method but this situation is same.

Thank you for interest.

Good works.

0 Kudos
1 Reply
Chris_P_Intel
Employee
814 Views

For checkboxes you use .prop("checked", true), not  .attr()

 http://stackoverflow.com/questions/15044340/jquery-set-checkbox-checked

 

And to change a value and have an event fired, you use $(domNode).val()   and for knowing when that has changed $(domNode).change()

https://api.jquery.com/change/

http://api.jquery.com/val/

Hope these help,

Chris

 

0 Kudos
Reply