Forum Discussion

lucas's avatar
lucas
Creator II
5 years ago
Solved

how to retrieve checkbox value from form ?

hello,

i have a form that needs to get user inputs. On this form there are text fields, check boxes and a validate button that runs the logic to retrive the inputs. I'm able to retrieve the text fields with a method that runs on the click of the validate button.

the code that works for the text fields:

var tolerance = getFieldByName("tolerance").getElementsByTagName("input")[0].value;

but the value i get when i use this same code with a checkbox is always " on " no matter if i tic the checkbox or not.

thanks,

Lucas

  • Hi Lucas,

    Can you try below code (replace bold letters with checkbox name)

    var tolerance = document.querySelector('input[name="tolerance"]').checked;

    alert(tolerance);

    You will get true if it is checked, else false in alert

    Thank You

    Gopikrishnan R

2 Replies

  • Hi Lucas,

    Can you try below code (replace bold letters with checkbox name)

    var tolerance = document.querySelector('input[name="tolerance"]').checked;

    alert(tolerance);

    You will get true if it is checked, else false in alert

    Thank You

    Gopikrishnan R

    • lucas's avatar
      lucas
      Creator II

      thank you it's working great