By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,016 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

input checkbox onclick not working via DOM on IE7, FF, WebKit

P: n/a
The following input checkbox onclick via DOM is not working on IE7, FF, or
WebKit, but is working on Opera for some strange reason.

http://www.aarongray.org/Test/JavaScript/checkbox.html

Here's the code :-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<script type="text/javascript" src="LibJS.js"></script>
</head>

<body onLoad="init()">

<script>

use( LibJS.HTML)

function init()
{
test = document.createElement( "INPUT")
test.type = "checkbox"
test.checked = true
test.onClick = "alert( 'test = ' + this.checked)"
// test.setAttribute( "onClick", "alert( 'test = ' + this.checked)")

document.body.appendChild( test)
}

</script>
</body>
</html>

Hope I have not missed something too silly.

Many thanks in advance,

Aaron
Oct 31 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Oct 31, 2:35 pm, Aaron Gray wrote:
The following input checkbox onclick via DOM is not
working on IE7, FF, or WebKit, but is working on Opera
for some strange reason.
<snip>
function init()
{
test = document.createElement( "INPUT")
test.type = "checkbox"
test.checked = true
test.onClick = "alert( 'test = ' + this.checked)"
<snip>
Hope I have not missed something too silly.
In case sensitive javascript the property name to which you should be
assigning is 'onclick' (all lower case), and the value you should be
assigning is a reference to a function object not a string primitive.

Richard.
Oct 31 '08 #2

P: n/a
"Richard Cornford" <Ri**************@googlemail.comwrote in message
news:b2**********************************@s9g2000p rm.googlegroups.com...
On Oct 31, 2:35 pm, Aaron Gray wrote:
>The following input checkbox onclick via DOM is not
working on IE7, FF, or WebKit, but is working on Opera
for some strange reason.
<snip>
>function init()
{
test = document.createElement( "INPUT")
test.type = "checkbox"
test.checked = true
test.onClick = "alert( 'test = ' + this.checked)"
<snip>
>Hope I have not missed something too silly.

In case sensitive javascript the property name to which you should be
assigning is 'onclick' (all lower case), and the value you should be
assigning is a reference to a function object not a string primitive.
"function object not a string primitive" thats the one, silly, silly me !

Have not done some JavaScript for a couple of weeks, amazing how quickly my
brain chucks things out.

Aaron
Oct 31 '08 #3

P: n/a
SAM
Le 10/31/08 4:32 PM, Aaron Gray a écrit :
"Richard Cornford" <Ri**************@googlemail.comwrote in message
news:b2**********************************@s9g2000p rm.googlegroups.com...
>On Oct 31, 2:35 pm, Aaron Gray wrote:
>>The following input checkbox onclick via DOM is not
working on IE7, FF, or WebKit, but is working on Opera
for some strange reason.
<snip>
>>function init()
{
test = document.createElement( "INPUT")
test.type = "checkbox"
test.checked = true
test.onClick = "alert( 'test = ' + this.checked)"
test.onclick = function() { alert('test = ' + this.checked); };
}
Have not done some JavaScript for a couple of weeks, amazing how quickly my
brain chucks things out.
--
sm

Oct 31 '08 #4

P: n/a
"SAM" <st*********************@wanadoo.fr.invalidwrote in message
news:49*********************@news.orange.fr...
Le 10/31/08 4:32 PM, Aaron Gray a écrit :
>"Richard Cornford" <Ri**************@googlemail.comwrote in message
news:b2**********************************@s9g2000 prm.googlegroups.com...
>>On Oct 31, 2:35 pm, Aaron Gray wrote:
The following input checkbox onclick via DOM is not
working on IE7, FF, or WebKit, but is working on Opera
for some strange reason.
<snip>
function init()
{
test = document.createElement( "INPUT")
test.type = "checkbox"
test.checked = true
test.onClick = "alert( 'test = ' + this.checked)"

test.onclick = function() { alert('test = ' + this.checked); };
}
>Have not done some JavaScript for a couple of weeks, amazing how quickly
my brain chucks things out.
Yes, thanks Sam, I now have everything working fine now :)

Aaron
Oct 31 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.