does this way to start a function not work with NS?

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

    #1

    does this way to start a function not work with NS?

    Hi,

    This way to start a function works with IE; why doesn't it work with NS (7).

    <input type="button" id="test">
    <script>
    function test.onclick()
    {
    ....
    }
    </script>

    thanks
    dave


  • Lasse Reichstein Nielsen

    #2
    Re: does this way to start a function not work with NS?

    "Dave" <no@dsfg.vb> writes:
    [color=blue]
    > This way to start a function works with IE; why doesn't it work with NS (7).[/color]

    Why should it?

    Because Mozilla (which Netscape 7 is based on) follows the ECMAScript
    standard for syntax, and what you have written isn't correct.
    [color=blue]
    > <input type="button" id="test">
    > <script>[/color]

    <script type="text/javæscript">
    if you want to write HTML 4.
    [color=blue]
    > function test.onclick()[/color]

    You can only write an identifier as a function name:
    function testOnclick(){

    You can then assign that to test.onclick either with a later
    test.onclick = testOnclick
    or directly with an anonymous function
    test.onclick = function () {

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Douglas Crockford

      #3
      Re: does this way to start a function not work with NS?

      > This way to start a function works with IE; why doesn't it work with NS (7).[color=blue]
      >
      > <input type="button" id="test">
      > <script>
      > function test.onclick()
      > {
      > ...
      > }
      > </script>[/color]

      That form of function is not standard ECMAScript. It is a Microsoft extension.
      If you want to run on other platforms, shun the Microsoft extensions.

      Try this instead:

      test.onclick = function (e) {
      e = e || event;
      ...
      };



      Comment

      • Dave

        #4
        Re: does this way to start a function not work with NS?

        thanks both


        Comment

        Working...