Select a radio / checkbox in JS

Aug 5, 2013
Select a radio / checkbox in JS
  • Code (Javascript):
    // get the div that contains the checkboxes
    // this div is the element which uses the elemnent's full name as its id.
    var div = $('tablename___elementname');
     
    //get its checkboxes
    var inputs = div.getElements('input[type=checkbox]');
     
    //or to get radiobuttons
    var inputs = div.getElements('input[type=radio]');
     
    //access a specific input and see if its checked or not
     
    if(inputs[0].checked){
        alert('the first input is checked')
    } else {
        alert('the first input in not checked');
    }