473,244 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,244 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 2546
dev7060
626 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

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

Similar topics

6
by: Angelos | last post by:
I have this list of logs stored in a MySQL DB. I display them in a list and next to each log I have a del view LINK I want to add Checkboxes next to each log and keep del and view links as...
1
by: hazz | last post by:
What do I do to capture the checkbox values as listed below in order to update the database table. There will be an ID field also contained in the row to use in the update query. What would I put...
7
by: bhargavigupta | last post by:
hi, In my application i have one checkbox when ever i am entering values to the page it has to store the values into the database table using insert statement , remaining values r...
10
by: LionsDome | last post by:
Hello, I have a vb.net page which a bunch of checkboxes. A user can select a checkbox(s) and hit the submit button to store those values in a SQL Server table. This works fine with no problem...
22
by: Mike1961 | last post by:
Checkbox values Hello. I have a problem with this code ASP / Javascript. The problem is JavaScript; try this LINK and select value cespiti 1) With ASP language is populated a secondary...
9
by: raamay | last post by:
I have six checkboxes as shown below: <table> <tr> <td><input name="spec1" type="checkbox" value="0" tabindex="11" /><label id="label">Bridge Construction</label></td> </tr> <tr> <td><input...
1
by: JSharma | last post by:
Hii Everyone I am having a problem while inserting the checkbox values into database after posting. I am actually getting the Checkbox fields from Database .Now I want to insert the Checked field...
1
by: issactang | last post by:
my checkbox values are in a associate values MY AIM IS: I want to get the check box value and refresh the selected item from a database; THE problem: My php scripts is not able to fetch chk...
5
by: bhitra | last post by:
Hi I have 3 groups of checkbox. One is for fruit platter, cake platter, wraps, .each has 7 checkboxes. I want to add unlimited number of groups and keep checkboxes. So i need a javascript to pass...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.