Help With JavaScript If Statement for Checkbox values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DADof3
    New Member
    • May 2021
    • 1

    Help With JavaScript If Statement for Checkbox values

    I have an issue where I need to set the value for checkboxes so that if the box is checked I pass a certain value and if the box is left unchecked i also pass a value.

    Right now the code I have written is working fine if the box is checked. I am not getting anything to pass when the box is unchecked.

    Here is the javascript i have written.

    Code:
               <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

    Code:
        response.write("<TD>")
        Response.Write("<INPUT type=checkbox id=WEEK1 name=" & idPOS & ">")
        response.write("</TD>")
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    I have an issue where I need to set the value for checkboxes so that if the box is checked I pass a certain value and if the box is left unchecked i also pass a value.

    Right now the code I have written is working fine if the box is checked. I am not getting anything to pass when the box is unchecked.
    If the user doesn't decide to interact with the checkbox, no event would be triggered.

    Comment

    Working...