user655334
user655334

Reputation: 1015

Dynamically set radio button active using jquery mobile

i am using jquery mobile horizontal control group radio buttons.

How do i set the first radio button active. The following are the two radio buttons,

<input type="radio" name="rating" id="radio-mini-1" value="Above Average" /><label for="radio-mini-1">Above<br /> Average</label>

Average

I tried using the following code,

$('input:radio[name="rating"]').filter('[value="Above Average"]').attr('checked', true);

but no luck. What's wrong?

Upvotes: 2

Views: 9071

Answers (5)

Ari Waisberg
Ari Waisberg

Reputation: 1304

For me it worked as simple as

$("#myItem").prop("checked", true)

I don't see so complicated as explained above...

Upvotes: -1

codepaladin
codepaladin

Reputation: 29

This function works nicely:

function set_jqm_radio_button( button_name, value ) {

$( 'input:radio[name="' + button_name + '"]' ).filter( '[value="' +value + '"]' ).prop( 'checked', true ).checkboxradio( 'refresh' );

}

Upvotes: 2

Tom Kincaid
Tom Kincaid

Reputation: 4975

You need to call refresh.

$(..selector...).attr("checked",true).checkboxradio("refresh"); 

Upvotes: 9

Porizm
Porizm

Reputation: 533

When you use jQueryMobile, the html structure changes, so you have to do some tricks, try this:

$('input:radio[name="rating"]').filter('[value="Above Average"]').next().click()


if it didn't work, try this:

$('input:radio[name="rating"]').filter('[value="Above Average"]').parent().find("label[for].ui-btn").click()

Upvotes: 7

Snake Eyes
Snake Eyes

Reputation: 16754

I don't know how works jquery mobile but try this

$('input:radio[name="rating"]').filter('[value="Above Average"]').prop('checked', true);

As reagten's suggestion, please paste HTML code and I'll update my answer.

But your code works fine: http://jsfiddle.net/dH69J/

Upvotes: -1

Related Questions