Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a click on a jQuery UI radio button?

I have some radio buttons

<div id="typeRadios">
    <input id="character_chartype_a" name="character[chartype]" type="radio" value="A" /><label for="character_chartype_a">A</label>
    <input id="character_chartype_a" name="character[chartype]" type="radio" value="B" /><label for="character_chartype_b">B</label>
</div>

that I turn into jQuery UI buttons

$("#typeRadios").buttonset();

What line of code can I use to simulate a click on one of the buttons? I've tried this

// here data.chartype equals "A"
$("input[value='"+data.chartype+"']").click();

but it doesn't work. Thanks for reading.

like image 751
ben Avatar asked Aug 29 '10 02:08

ben


2 Answers

You have to do it with the label element added by jQuery UI. Try:

$("label[for='character_chartype_"+data.chartype+"']").click();

Have a look at it here, in a controlled environment: http://jsfiddle.net/B3d4z/

like image 133
Yi Jiang Avatar answered Oct 12 '22 13:10

Yi Jiang


I believe you're looking for the select event.

$("input[value='"+data.chartype+"']").select();
like image 1
Jacob Relkin Avatar answered Oct 12 '22 13:10

Jacob Relkin