Solved

Newb needs help Checking checkbox values

Posted on 2008-06-11
6
170 Views
Last Modified: 2010-04-21
I am trying to check the value of a checkbox being passed but have yet to get the correct syntax for this. I have a form that does some simple checking of other form elements such as text fields, textareas, radio buttons and so on. Of course what I am using to check these elements doesn't work for me on checkboxes.

if(document.myform.thischeckbox.value == 'mypredfinedvalue'){
 alert("Do this");
}

I know it's simple, I just need to see the correct syntax for doing this to get in my head.

TIA

Bewildered Bob
0
Comment
Question by:Bimperial
  • 3
  • 3
6 Comments
 
LVL 6

Expert Comment

by:ysfx
ID: 21763349
if (document.myform.thischeckbox.checked)
0
 

Author Comment

by:Bimperial
ID: 21775880
This doesn't seem to work or doesn't behave like I would expect it to or need for it to. I have a series of checkboxes with the same name and different values like the one below and I am trying to check to see if the checkbox with the value "Other" has been checked, if it has I return false and run my error message.

<input type="checkbox" name="TOXICOLOGY" value="Valproate" />
<input type="checkbox" name="TOXICOLOGY" value="Lithium" />
<input type="checkbox" name="TOXICOLOGY" value="Urine tox screen" />
<input type="checkbox" name="TOXICOLOGY" value="Confirmatory test for opiates" />
<input type="checkbox" name="TOXICOLOGY" value="Other"  />
0
 
LVL 6

Expert Comment

by:ysfx
ID: 21786455
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Bimperial
ID: 21793184
I have googled this and looked at many references without success at finding the solution. As I stated in my original question and request for help:
"I just need to see the correct syntax for doing this to get in my head."

Not another reference to how this button works or that element works as I have tried all the examples I've found in my searches and tried what I thought would work and of course it doesn't.
0
 
LVL 6

Accepted Solution

by:
ysfx earned 50 total points
ID: 21794651
document.myform.TOXICOLOGY[i].value
where 'i' is the index of the element.
0
 

Author Closing Comment

by:Bimperial
ID: 31466293
Thank you so much! This is what I needed being a visual learner it will stick with me and now I know the syntax on how to access the value of a checkbox.

Thanks again!

Bob
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now