Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reading checked state of checkbox

Community Beginner ,
Jan 17, 2007 Jan 17, 2007
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!
TOPICS
Server side applications
262
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 18, 2007 Jan 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
Translate
LEGEND ,
Jan 17, 2007 Jan 17, 2007
Try

if (checkState)
{
statements
}


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





Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 18, 2007 Jan 18, 2007
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines