Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing checkbox value with onclick 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Code:
<input type="checkbox" onClick="foo(this.value);" />

...

function foo(someValue)
{
  alert(someValue);
}

Always pops up on, never off or undefined, or a blank string or whatever I should be expecting for the off value.

ANy idea why, and any idea what the fix may be?
 
do you want to use
Code:
onClick='foo(this.checked)'

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Well apparently using this.checked sends a boolean I can deal with... still a little surprised that this.value doesn't work.
 
heh, we solved it at the same time.... well within a second anyway... thanks.
 
If you don't provide a value in a checkbox, the default is on. Your example doesn't show a value in the checkbox.

Lee
 
Ah right, just cause value sounds like it would be on/off... in fact, value is just another attribute and it defaults to on for checkboxes... .checked is the actual stateful holder of checkboxes and radio buttons (if I'm not mistaken) to find out if they're actually on or not.

THanks for the explanation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top