Reputation: 13
So I got this bit of code where if I click a radio button I want these other radio buttons to be unclicked if they are cliked and also to be disabled.
So far they get disabled but however they do not get unclicked?
if (document.getElementById("None").checked) {
document.getElementById("HundredsAndThousands").clicked = false;
document.getElementById("ChocolateSprinkles").clicked = false;
document.getElementById("SilverBalls").clicked = false;
document.getElementById("Coconut").clicked = false;
document.getElementById("HundredsAndThousands").disabled = true;
document.getElementById("ChocolateSprinkles").disabled = true;
document.getElementById("SilverBalls").disabled = true;
document.getElementById("Coconut").disabled = true;
}
Upvotes: 1
Views: 335
Reputation: 4042
This can be done so much better, if you use a jQuery library. You can use .val()
or .attr()
to get the value of the radio button.
var str = $("#none").attr('checked');
var str = $("input:radio[name=radioname]:checked").val();
And .attr('checked', true);
to change a radio button from checked (to unchecked). To change this on a group
$("input:radio[name=mygroup]").attr('checked',true);
Upvotes: 1
Reputation: 71918
The property you need to change is called checked
, not clicked
:
document.getElementById("HundredsAndThousands").checked = false;
document.getElementById("ChocolateSprinkles").checked = false;
document.getElementById("SilverBalls").checked = false;
document.getElementById("Coconut").checked = false;
Upvotes: 1