Reputation: 381
I am looking to have a radio button that is ONLY triggered by the "onclick" of a select option. I do not want the user to be able to manually change the radio button. Is there a way to make this happen. This is the code I have for the radio button to change (it works), but the user may still change it after the fact:
$("#button1").prop('checked',true);
$("#strategies").mouseup(function() {
if(strat == $("#strategies").val()) {
$("#button1").prop('checked',true);
$("#why").hide();
$("#whyNo").show();
}
else {
$("#button2").prop('checked',true);
$("#whyNo").hide();
$("#why").show();
}
});
html:
<input type="radio" id="button1" name="switch" value="0">No Switch<br>
<input type="radio" id="button2" name="switch" value="1">Switch<br>
Any suggestions would be greatly appreciated.
Upvotes: 0
Views: 132
Reputation: 3884
In HTML, there's an attribute for input fields called disabled. I'm not certain how to manipulate it in Javascript, however.
<input type="radio" disabled>
or
<input type="radio" disabled="disabled">
Keep in mind, some browsers may render it as "greyed out."
Upvotes: 3
Reputation: 12341
Have you tried this?
$('input[name="switch"]').click(function () {
return false;
});
Upvotes: 0