I need to set a radio button (‘no_subscribe’) to true when all the elements, ‘checkbox’ are unchecked. This should happen after unchecking all these checkboxes.
Forgive me if this has been asked elsewhere. I am new to javascript and programming in general, so any help is greatly appreciated! I have been able to make the ‘subscribe’ button do what I want, but I can’t figure out the opposite scenario. These are inside a form called ‘mailer’. I recently deleted the attempts I have made. They were not working, so I am sorry there is no code to troubleshoot.
<fieldset>
Subscribe to our Mailing List?
<input type = "radio" name = "yes" id = "subscribe" onclick = "subscribe_to_all();" value = "yes" />Yes
<input type = "radio" name = "no" id = "no_subscribe" onclick = "subscribe_to_none();" value = "no" />No
</fieldset>
<fieldset name = "subscribe">
<legend>Mailing List Subscriptions</legend>
<input type="checkbox" id = "c1" name="subscriptions" onclick = "radio_yes();" value="CorporateEmails"/>
Corporate Press Release Emails<br />
<input type="checkbox" id = "c2" name="subscriptions" onclick = "radio_yes();" value="SoftwareAdvertising"/>
Upgrade Software Advertising List<br />
<input type="checkbox" id = "c3" name="subscriptions" onclick = "radio_yes();" value="PostBuyoutSpammers"/>
List given to spammers after buyout<br />
<input type="checkbox" id = "c4" name="subscriptions" onclick = "radio_yes();" value="NonCynical"/>
The only non-cynical list<br />
<input type="checkbox" id = "c5" name="subscriptions" onclick = "radio_yes();" value="SelltoSpammers"/>
List to sell to spammers<br />
<input type="checkbox" id = "c6" name="subscriptions" onclick = "radio_yes();" value="SpamList"/>
Spam List<br />
External javascript file:
function subscribe_to_all() {
for (i = 0; i < document.mailer.subscriptions.length; i++) {
document.mailer.subscriptions[i].checked = true;
}
}
function subscribe_to_none() {
for (i = 0; i < document.mailer.subscriptions.length; i++) {
document.mailer.subscriptions[i].checked = false;
}
}
function radio_yes() {
document.getElementById("subscribe").checked = true;
}
I’ve used a new function. It is not optimized . I’ve used a new function. There you can fetchthe checkbox status in a loop. But my code works. Just copy and paste and see the changes