471,122 Members | 1,115 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,122 software developers and data experts.

Help With JavaScript If Statement for Checkbox values

1
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.

Expand|Select|Wrap|Line Numbers
  1.            <SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
  2.  
  3.         const checkbox = document.getElementById("WEEK1")
  4.  
  5.         checkbox.addEventListener('click', (event) => {
  6.           if (event.currentTarget.checked) {
  7.             document.getElementById("WEEK1").value = "Its ON";
  8.  
  9.           } else {
  10.             document.getElementById("WEEK1").value = "Its OFF";
  11.  
  12.           }
  13.         })
  14.     </SCRIPT>
  15.  

Here is the code for my checkbox

Expand|Select|Wrap|Line Numbers
  1.  
  2.     response.write("<TD>")
  3.     Response.Write("<INPUT type=checkbox id=WEEK1 name=" & idPOS & ">")
  4.     response.write("</TD>")
  5.  
  6.  
  7.  
May 3 '21 #1
1 2292
dev7060
583 Expert 512MB
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.
May 6 '21 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Angelos | last post: by
10 posts views Thread by LionsDome | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.