0

When a user clicks on my radio button:

<input type="radio" name="allselect" onClick="javascript: _select('none');" />

I need the function _select(param) to find every radio button with a value of param, so 'none' in this case, and click it. How can this be done in jquery?

user740521
  • 1,175
  • 4
  • 12
  • 25
  • What have you tried so far and what in particular do you have problems with? jQuery's documentation is the place to start: http://api.jquery.com/, especially have a look at selectors: http://api.jquery.com/category/selectors/ – Felix Kling Jan 19 '12 at 19:19
  • I looked at the .find function but I didn't see anyway to say 'find all elements WHERE value is this' – user740521 Jan 19 '12 at 19:19
  • 2
    possible duplicate of [JQuery - find a radio button by value](http://stackoverflow.com/questions/2173527/jquery-find-a-radio-button-by-value) – Felix Kling Jan 19 '12 at 19:20

5 Answers5

2

Since you are using jQuery:

<input type="radio" name="allselect" id="selectnone" />

JS:

$('#selectnone').click(function(){
    $('input[type=checkbox]').each(function(){
          if(this.value === 'none') this.checked = true;
    });
});
Naftali
  • 144,921
  • 39
  • 244
  • 303
1

I'd think that the following, as yet untested approach, would work:

$('input:radio').click(
    function(){
        var inputsOfValueEqualToNone = $('input:radio[value="none"]');
    });

Making the above into a more function-based approach:

function _select(param){
    if (!param){
        return false;
    }
    else {
        inputs = $('input:radio[value="' + param + '"]').click();
    }
}

References:

David Thomas
  • 249,100
  • 51
  • 377
  • 410
0

Try this

function _select(param){
   var rBtns = $('input[name=' + param + ']');
   rBtns.click();//Calling the click method on all the radio buttons it found
}
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
0

You can do this:

function _select(paramVal){
   $('input[value=' +paramVal +']').trigger('click');
}
kleinohad
  • 5,800
  • 2
  • 26
  • 34
0

Use:

function _select( value ) {
  var elems $('input:radio[value='+value+']'); // all the radio buttons with the value
}
Wouter J
  • 41,455
  • 15
  • 107
  • 112