Solved

Newb needs help Checking checkbox values

Posted on 2008-06-11
6
173 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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