Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #11974

Re: onclick=function(){obj.meth()}

From "Richard Cornford" <Richard@litotes.demon.co.uk>
Newsgroups comp.lang.javascript
References <jp45k75qbcjbb5v8tavnmognds11hjihdh@4ax.com> <4f429d06$0$6981$e4fe514c@news2.news.xs4all.nl> <9qflqrFfeeU1@mid.uni-berlin.de>
Subject Re: onclick=function(){obj.meth()}
Date 2012-02-21 00:34 +0000
Message-ID <_56dnWhXdrA-e9_SnZ2dnUVZ8ridnZ2d@giganews.com> (permalink)

Show all headers | View raw


Jake Jarvis wrote:
> On 20.02.2012 20:20, Tom de Neef wrote:
>> Puzzled schreef:
>>>
>>> function row( i )
>>> {
>>>     var rec_s  = '<tr><td><a href="javascript:void(0);" '+
>>>         'id="foo'+i+'" '+
>>>         'onclick=function(){alert('+i+')}>'+i+'</a>'+
>>> '</td></tr>';
>>>     return rec_s ;
>>> }
>>>
>>
>> This function compiles in FF and JSlint doesn't complain either.
>>
>
> It's not about just compiling/passing as syntactically valid js
> program on the first level, the real problem manifests itself
> "later", when actually clicking the resulting anchor.

As you say, the real problem will manifest itself later, but that later 
will not be when anchor is clicked.  The issue here is a syntax error; 
an Expression statement is forbidden from commencing with the - 
function - keyword by the language's syntax rules, because that would be 
ambiguous with a function declaration. And the point when that syntax 
error will manifest itself will be when the javascript string defined in 
the function above is processed through an HTML parser (probably via the 
use of innerHTML, but maybe - document.write -). At that point the 
browser must use the text of the - ONCLICK - attribute in the HTML to 
create a javascript function object to assign to the DOM element 
representation's - onclick - property, which is will not be able to do 
because the HTML attribute value contains a javascript syntax error.

Richard. 

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 14:02 -0500
  Re: onclick=function(){obj.meth()} "Tom de Neef" <tdeneef@qolor.nl> - 2012-02-20 20:20 +0100
    Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 20:39 +0100
      Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:34 +0000
        Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:13 +0100
          Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:05 -0800
        Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:47 +0100
          Re: onclick=function(){obj.meth()} John G Harris <john@nospam.demon.co.uk> - 2012-02-21 15:59 +0000
  Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 21:09 +0100
    Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-20 20:29 +0000
      Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 16:50 -0500
        Re: onclick=function(){obj.meth()} "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-02-21 11:33 +0000
    Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 15:47 -0500
      Re: onclick=function(){obj.meth()} Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-02-20 22:38 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:12 -0500
      Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 14:04 -0800
        "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 01:37 +0100
          Re: "The this value" (Was: onclick=function(){obj.meth()}) Gene Wirchenko <genew@ocis.net> - 2012-02-20 17:20 -0800
          Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:44 +0100
            Re: "The this value" (Was: onclick=function(){obj.meth()}) Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 22:31 +0100
              Re: "The this value" (Was: onclick=function(){obj.meth()}) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-22 10:55 +0100
                Re: "The this value" (Was: onclick=function(){obj.meth()}) John G Harris <john@nospam.demon.co.uk> - 2012-02-22 15:58 +0000
        Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:30 +0000
      Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-20 13:43 -0800
      Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-20 23:17 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-20 17:48 -0500
          Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 00:57 +0100
          Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 01:03 +0000
            Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-20 19:05 -0800
              Re: onclick=function(){obj.meth()} Richard Cornford <Richard@litotes.demon.co.uk> - 2012-02-21 04:14 -0800
                Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 13:54 +0100
                Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 10:17 -0800
                Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:57 -0800
                Re: onclick=function(){obj.meth()} Gene Wirchenko <genew@ocis.net> - 2012-02-21 13:39 -0800
                Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-22 05:07 -0800
            Re: onclick=function(){obj.meth()} Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-21 12:58 +0100
        Re: onclick=function(){obj.meth()} "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-21 00:45 +0000
          Re: onclick=function(){obj.meth()} Stefan Weiss <krewecherl@gmail.com> - 2012-02-21 02:22 +0100
        Re: onclick=function(){obj.meth()} Puzzled <scratching.head@example.com> - 2012-02-21 08:12 -0500
          Re: onclick=function(){obj.meth()} Scott Sauyet <scott.sauyet@gmail.com> - 2012-02-21 11:14 -0800

csiph-web