I have searched for the answer but all I got couldn't solve my problem.
I want to checked
a radio input
like this
<input type="radio" name="field" value="a" />
<input type="radio" name="field" value="b" checked />
<input type="radio" name="field" value="c" />
<a href="javascript:;">cancel</a>
// jQuery
$("a").click(function(){
var checked = "b";
$('input').each(function(){
var value = $(this).val();
if(value == checked){
$(this).attr('checked', true);
} else {
$(this).attr('checked', false);
}
});
});
Now this is what I want to achieve, the default value is "b" so if a user clicks "a" or "c" and wants to return the value back to "b" without clicking "b" and clicks the link I want the value "b" to be checked and thereby unchecking the other values. But when I run the code, it just uncheck all the values. How can I achieve this using jQuery