topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday November 8, 2024, 7:58 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: How to tell if any check boxes are checked?  (Read 4014 times)

OptimalDesigns

  • Supporting Member
  • Joined in 2018
  • **
  • Posts: 70
  • (retired) Mathematical Engineer
    • View Profile
    • Calculus (level) Problem Solving; Examples & Compiler
    • Read more about this member.
    • Donate to Member
How to tell if any check boxes are checked?
« on: July 16, 2020, 06:54 PM »
I have several check boxes a user can select for various classes. If one or more check boxes are selected, then ooo . Please test it. Here is the html code at present:
</script>
    function myHideShow() {

    var checkboxes = document.getElementById("interest[]");
    var user = document.getElementById("username");
    var email = document.getElementById("email");
    var submit = document.getElementById("submit");

    if ((checkboxes.checked)) {
//      echo("You didn't select any check boxes.");
        user.disabled = true;
        email.disabled = true;
        submit.disabled = true; }
    else {
//      echo("You did select at least one check box.");
        user.disabled = false;
        email.disabled = false;
        submit.disabled = false;
    }
  }
</script>

<!DOCTYPE html> <html> <head> </head> <body>
  <form name='calculusclassform' method="post" action="">
    <fieldset>
      <legend>Choose your <b>Class</b> interests</legend>
      <input type="checkbox" id="oil" name="interest[]" value="Oil Refinery Optimization" onclick="myHideShow()">
      <label for="oil">Oil Refinery Optimization</label>
      <span>Crude oil ...</span>

<p id="text" style="display:none">Checkbox is CHECKED!</p>

      <input type="checkbox" id="curvfit" name="interest[]" value="Curve Fitting Data sets" onclick="myHideShow()">
      <label for="curvfit">Curve Fitting Data sets</label>
      <span>Have a curve fitting problem? ...</span>
      <input type="checkbox" id="coding" name="interest[]" value="Calculus-level Coding" onclick="myHideShow()">
      <label for="coding">Calculus-level Coding</label>
      <span> languages ... </span>
      <h3>Classes are free, but in return, we ask you to share these class offerings with 5+ others.  Thanks.</h3>
      <span>             Name:</span>
      <input type="name" name="username" id="username" disabled><br>
      Email Address:
      <input type="email" name="email" id="email" disabled><br><br>
      <input type="submit" value="Submit" id="submit" disabled>
    </fieldset>
  </form>
</body> </html>

Running this JS script code if ((checkboxes.checked)) is my problem. Ideas? Trying to test if any checkboxes are checked.
« Last Edit: July 20, 2020, 06:24 PM by OptimalDesigns, Reason: updating code, changed title, and intro text. »