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?

3
  • What have you tried so far and what in particular do you have problems with? jQuery's documentation is the place to start: api.jquery.com, especially have a look at selectors: api.jquery.com/category/selectors Commented Jan 19, 2012 at 19:19
  • I looked at the .find function but I didn't see anyway to say 'find all elements WHERE value is this' Commented Jan 19, 2012 at 19:19
  • 2
    possible duplicate of JQuery - find a radio button by value Commented Jan 19, 2012 at 19:20

5 Answers 5

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;
    });
});
Sign up to request clarification or add additional context in comments.

Comments

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:

Comments

0

Try this

function _select(param){
   var rBtns = $('input[name=' + param + ']');
   rBtns.click();//Calling the click method on all the radio buttons it found
}

Comments

0

You can do this:

function _select(paramVal){
   $('input[value=' +paramVal +']').trigger('click');
}

Comments

0

Use:

function _select( value ) {
  var elems $('input:radio[value='+value+']'); // all the radio buttons with the value
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.