468,490 Members | 2,603 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

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 1570
dev7060
430 Expert 256MB
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
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.