select (or click) specific radiobutton using jQuery
Posted
by
Oleg Babanov
on Stack Overflow
See other posts from Stack Overflow
or by Oleg Babanov
Published on 2011-02-27T23:16:47Z
Indexed on
2011/02/27
23:24 UTC
Read the original article
Hit count: 185
jQuery
|radio-button
I am trying to make specific radiobutton checked on page load and tried a lot of ways, but no one worked for me. This is a part of orderform on my webstore.
<input type="radio" name="sPaymentCarrier" id="pC_2-1" value="1;2;0.00"
onclick="countCarrierPrice( this )" />
<label for="pC_2-1">0</label>
Actually this radiobutton is the only on radiobutton on page, and it must be checked to let user make order.
I tried
$(function() {
var $radios = $('input:radio[name=sPaymentCarrier]');
if($radios.is(':checked') === false) {
$radios.filter('[value=1;2;0.00]').attr('checked', true);
}
});
and
$('input:radio[name="sPaymentCarrier"]').filter('[value="1;2;0.00"]').attr('checked', true);
but none of these ways worked. Also I tried a lot of other codes, but when I refreshed page I still saw this button unchecked. I guess maybe I have to set up jquery click on this button instead of select, but actually I cannot make this work.
Any help is appreciated!
© Stack Overflow or respective owner