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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't capture the checbox click. 4

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
US
HI all,

I have a form, with a checkbox named "chkBold". A JS routine should simply alert "false" or "true". But nothing works. Does anyone see anything wrong with this? I just entered the most pertinent lines here. The form is full of fields that validate fine, but not this check box. Thanks! Here is the code:


<script type="text/javascript" "language="javascript">
function boldonoff() {
If (document.frmPageCreate.chkBold.checked==false)
{
alert ("false");
} else {
alert ("true");
}
}
</script>

---------------------------------------
(this is inside of <Form Name="frmPageCreate">)

<Input Type="checkbox" Name="chkBold" onClick=boldonoff()>Bold?</Input>
 
no need for explicit reference. change function to

Code:
function boldonoff(cb) {
    alert(cb.checked);
}

change checkbox to

Code:
<input type="checkbox" name="chkBold" onclick="boldonoff(this)" />Bold?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Pass a reference to the object you've just clicked, that would be the easiest way to do it. Also, javascript is case sensitive - it should be "if", not "If":
Code:
<script type="text/javascript" "language="javascript">
function boldonoff([!]obj[/!]) {
[!]i[/!]f ([!]obj.clicked[/!])
{
alert ("true");
} else {
alert ("false");
}
}
</script>

---------------------------------------
(this is inside of <Form Name="frmPageCreate">)

<Input Type="checkbox" Name="chkBold" onClick="boldonoff([!]this[/!])">Bold?</Input>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Javascript is case sensitive:
Code:
function boldonoff() {
[!]I[/!]f (document.frmPageCreate.chkBold.checked==false) 
{
alert ("false");
Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
I suck.... [cry]

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top