• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Newb needs help Checking checkbox values

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
Bimperial
Asked:
Bimperial
  • 3
  • 3
1 Solution
 
ysfxCommented:
if (document.myform.thischeckbox.checked)
0
 
BimperialAuthor Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BimperialAuthor Commented:
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
 
ysfxCommented:
document.myform.TOXICOLOGY[i].value
where 'i' is the index of the element.
0
 
BimperialAuthor Commented:
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now