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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Aaron Gray

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

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



    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.create Element( "INPUT")
    test.type = "checkbox"
    test.checked = true
    test.onClick = "alert( 'test = ' + this.checked)"
    // test.setAttribu te( "onClick", "alert( 'test = ' + this.checked)")

    document.body.a ppendChild( test)
    }

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

    Hope I have not missed something too silly.

    Many thanks in advance,

    Aaron


  • Richard Cornford

    #2
    Re: input checkbox onclick not working via DOM on IE7, FF, WebKit

    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.create Element( "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.

    Comment

    • Aaron Gray

      #3
      Re: input checkbox onclick not working via DOM on IE7, FF, WebKit

      "Richard Cornford" <Richard.Cornfo rd@googlemail.c omwrote in message
      news:b29caec3-a504-4663-b98f-0d17e5c8d0d6@s9 g2000prm.google groups.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.create Element( "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


      Comment

      • SAM

        #4
        Re: input checkbox onclick not working via DOM on IE7, FF, WebKit

        Le 10/31/08 4:32 PM, Aaron Gray a écrit :
        "Richard Cornford" <Richard.Cornfo rd@googlemail.c omwrote in message
        news:b29caec3-a504-4663-b98f-0d17e5c8d0d6@s9 g2000prm.google groups.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.create Element( "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

        Comment

        • Aaron Gray

          #5
          Re: input checkbox onclick not working via DOM on IE7, FF, WebKit

          "SAM" <stephanemoriau x.NoAdmin@wanad oo.fr.invalidwr ote in message
          news:490b2797$0 $888$ba4acef3@n ews.orange.fr.. .
          Le 10/31/08 4:32 PM, Aaron Gray a écrit :
          >"Richard Cornford" <Richard.Cornfo rd@googlemail.c omwrote in message
          >news:b29caec 3-a504-4663-b98f-0d17e5c8d0d6@s9 g2000prm.google groups.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.create Element( "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


          Comment

          Working...