Solved

Newb needs help Checking checkbox values

Posted on 2008-06-11
6
171 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
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.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Sheets Script 21 58
Download a website to hdd 2 52
Recordset containing single quotes 8 24
Get the number of current month days 2 11
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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

864 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

16 Experts available now in Live!

Get 1:1 Help Now