2 Replies Latest reply on Oct 3, 2014 9:49 AM by Rlattimer

    Assigning checkboxes value based on checked=true/false

    Rlattimer

      hello,

       

      i am entirely new to this, so I apologize if this is very wrong.

       

      I am trying to create an eForm that users can fill out, such that their checkbox selections will generate an integer value. this is a test form to look at the code, but this is what i have so far.. essentially I wanted to make variables which were dependent upon a checkbox's status, and assigned a value accordingly, which could then be summed across a range of checkboxes.

       

       

      <!-- code below -->

       

       

      <html>

      <head>

      <script type="text/javascript">

       

       

      var x = function() {

        if (document.getElementById("box1").checked=true {

        x=1;

        }

        else {

        x=0;

        }

       

      var y = function() {

        if (document.getElementById("box2").checked=true {

        y=1;

        }

        else {

        y=0;

        }

       

      var z = function() {

        if (document.getElementById("box3").checked=true {

        z=1;

        }

        else {

        z=0;

        }

       

       

       

      function total() {

        parseInt(x) + parseInt(y) + parseInt(z);

        }

       

       

       

       

      </head>

      <body>

       

       

      <input type="checkbox" id="box1" onkeyup="total()">

       

       

      <input type="checkbox" id="box2" onkeyup="total()">

       

       

      <input type="checkbox" id="box3" onkeyup="total()">

       

       

      <input type="text" id="total">

       

       

       

       

       

       

      </body>

      </html>

      <!-- code ends -->

       

       

      any help would be greatly appreciated!

       

      Regards,

      Rory