473,386 Members | 1,710 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,386 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 2557
dev7060
636 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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.