Skip to main content
New Participant
January 17, 2007
Answered

Reading checked state of checkbox

  • January 17, 2007
  • 1 reply
  • 294 views
Hi there:-

'Sorry to post such a simple question but I can find the answer in the Dreamweaver online reference, and I have wasted a lot of time trying to find the answer.
I want to read the checked state of a given checkbox and then if value of true is returned invoke function "A" or if false is returned invoke function "B".
Based on what I found in the reference I set up a variable to capture the state of the checkbox as follows:

function checkboxState()
{
var checkState = document.all.nameOfCheckbox.checked;
if (checkState == true)
{
statements
}
else
if (checkState == false)
{
statements
}

}

The check box is setup as follows:
<input name="nameOfCheckbox" type="checkbox" onClick="checkboxState()">

This doesn't work and I don't know why. I wondered if I had to define the checkbox in a particular way, e.g. using the value attribute or something, but the reference did not indicate this.

If anyone can help I would appreciate it.
Thanks!
This topic has been closed for replies.
Correct answer LJKerley
Hi Jules,
Thanks for the tip. It worked. I have seen people set up an if statement without any argument "if(checkStatus)" but I don't entirely understand the mechanics of what this is doing. (That is, how a true or false is passed to the variable) But I originally learned to code COBOL so maybe I am too old fashioned.
Thanks,
Linda

1 reply

Inspiring
January 17, 2007
Try

if (checkState)
{
statements
}


--
Jules
http://www.charon.co.uk/charoncart
Charon Cart 3
Shopping Cart Extension for Dreamweaver MX/MX 2004





LJKerleyAuthorCorrect answer
New Participant
January 18, 2007
Hi Jules,
Thanks for the tip. It worked. I have seen people set up an if statement without any argument "if(checkStatus)" but I don't entirely understand the mechanics of what this is doing. (That is, how a true or false is passed to the variable) But I originally learned to code COBOL so maybe I am too old fashioned.
Thanks,
Linda