?
Solved

Newb needs help Checking checkbox values

Posted on 2008-06-11
6
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 

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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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…
Suggested Courses

764 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