0

I wrote the following javascript to attempt to set the value of a check box to either ON or OFF depending on the status of the check box. However the value I am assigning when the checkbox is NOT checked is not being passed. If I select the box I see "Its On" being passed.

Here is the JavaScript i wrote

        <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
    
    const checkbox = document.getElementById("WEEK1")
    
    checkbox.addEventListener('click', (event) => {
      if (event.currentTarget.checked) {
        document.getElementById("WEEK1").value = "Its ON";

      } else {
        document.getElementById("WEEK1").value = "Its OFF";
    
      }
    })
</SCRIPT>

Here is the code for my checkbox

response.write("<TD>")
Response.Write("<INPUT type=checkbox id=WEEK1 name=" & idPOS & ">")
response.write("</TD>")
  • 1
    are you trying to modify the DOM according to the condition value? i think you are trying to do what `document.getElementById("WEEK1").value` . Also `type` and `id` values must be quoted. – charmful0x May 03 '21 at 02:36
  • I'd suggest using the _change_ event instead of _click_ – Phil May 03 '21 at 02:36
  • Also, this is not the best way to handle checked / unchecked checkbox values. See [this answer](https://stackoverflow.com/a/1992745/283366) – Phil May 03 '21 at 02:38
  • Hi Phil using the hidden solution does not work for me in this scenario. It results in two values being passed when the box is checked. Also i run into issue with how the page is setup to generate the name field of the input fields. – ThatGuy5 May 03 '21 at 02:51

0 Answers0