Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8938729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:41:50+00:00 2026-06-15T10:41:50+00:00

edit: Contacted the prof; I’m not actually [supposed] to use jQuery on this assignment

  • 0

edit: Contacted the prof; I’m not actually [supposed] to use jQuery on this assignment as the action on the form (e.g. prof’s website) doesn’t allow for it. Tyvm to all who replied so quickly and helpfully. Therefore, I am interested in a pure, native JS soln. to resolving these difficulties:

getting a group of checkboxes to toggle “on or off” based on whether the user clicks “Yes” or “No” radio button in a DOM-oriented form. Here’s the HTML for (I: the radio buttons, II: the checkboxes):

I:) Radio Buttons

<label> Subscribe to our Mailing List? </label>
   <input type="radio" name="raydeo" id="rad1" value="Yes" onclick="subscribe()"></input> 
        <label>Yes</label>
   <input type="radio" name="raydeo" id="rad2" value="No" onclick="subscribe()"></input> 
        <label>No</label>

II.) Checkboxes

<fieldset>
    <legend>Mailing List Subscriptions</legend>
    <br />
    <input type="checkbox" name="mailinglist" value="Corporate Press Release Emails" id="cor"></input><label> Corporate Press Release Emails</label>
    <br />
    <input type="checkbox" name="mailinglist" value="Upgrade Software Advertising List" id="sof"></input><label> Upgrade Software Advertising List</label>
    <br />
    <input type="checkbox" name="mailinglist" value="List given to spammers after buyout" id="lspa"></input><label> List given to spammers after buyout</label>
    <br />
    <input type="checkbox" name="mailinglist" value="The only non-cynical list" id="cyn"></input><label> The only non-cynical list</label>
    <br />
    <input type="checkbox" name="mailinglist" value="List to sell to spammers" id="tos"></input><label> List to sell to spammers</label>
    <br />
    <input type="checkbox" name="mailinglist" value="Spam List" id="spal"></input><label> Spam List</label>
    <br />
        </fieldset>

Using the rationale provided in posts such as Populating Checkboxes Based on Radio Button Click, which still uses jQuery, the best attempt I have made thus far is:

<script>
function subscribe(){
  //var yesPlease = document.getElementById("rad1");
  //var noThx = document.getElementById("rad2");
   var arr = new Array["cor", "sof", "lspa", "cyn", "tos", "spal"];
     //var hold = document.getElementById(arr[i]);
     //if(hold.getAttribute(arr[i]).checked = true && arr[i] >= 1){
     //document.getElementById("cor").innerHTML=hold.getAttribute("checked");
    var hold = document.getElementsByName("mailinglist")[0];

    for(var i = 0; i < arr.length; i++)
    {
      if(document.getElementById("rad1").checked==true)
      {
          hold.getAttribute(arr[i]).checked == true;
      }
        else if(document.getElementById("rad2").checked==true)
        {
            hold.getAttribute(arr[i]).checked == false;
        }
    }
}
</script>

When I load my document and click on either, nothing happens. Here’s the screenshot of the concerned section if it helps:thanks:

Mailing List Subscriptions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:41:51+00:00Added an answer on June 15, 2026 at 10:41 am

    You need to an action handler when the radio button is clicked. So that the element attribute “checked” is correctly updated upon clicking.

    The code below is edited from yours to just include the click handler on all input type radio

    $(document).ready(function(){
    function subscribe() {
        $('input[type="radio"]').click(function(){
            var yesPlease = document.getElementById("rad1");
            var noThx = document.getElementById("rad2");
            if(yesPlease.checked == true){
                //check all boxes
                $("#cor").prop("checked", true);
                $("#sof").prop("checked", true);
                $("#lspa").prop("checked", true);
                $("#cyn").prop("checked", true);
                $("#tos").prop("checked", true);
                $("#spal").prop("checked", true);
            }
            else if(noThx.checked == true) {
                //uncheck all boxes
                $("#cor").prop("checked", false);
                $("#sof").prop("checked", false);
                $("#lspa").prop("checked", false);
                $("#cyn").prop("checked", false);
                $("#tos").prop("checked", false);
                $("#spal").prop("checked", false);
            }
        });
    }
    subscribe();
    ​});​
    

    JSFiddle: http://jsfiddle.net/MSZtx/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
Edit (updated question) I have a simple C program: // it is not important
EDIT : It turned out that this can only be done through an external
Possible Duplicate: php edit for Cufon font replacement I am reposting this due to
I have developed one code to edit contact but it is not working in
total beginner to spring mvc. I need to prepopulate edit form in springmvc frame-work.
I'm not sure how to explain this one. I submitted an update of one
this question is not about code, at least not about code that gives errors.
Let's explain the context: I have a person form inside a jquery dialog that
EDIT: Parsed the array completely (it contained unparsed JSON!) array(22) { [0]=> array(4) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.