Featured post
javascript - Unexpected token } -
i have script open model window.. chrome gives me "uncaught syntaxerror: unexpected token }" on line doesn't have closing curly brace.
here portion of script has error:
function showm(id1){ window.onscroll=function(){document.getelementbyid(id1).style.top=document.body.scrolltop;}; document.getelementbyid(id1).style.display="block"; document.getelementbyid(id1).style.top=document.body.scrolltop; }
does have ideas on this? appreciated.
try running entire script through jslint. may point @ cause of error.
edit ok, it's not quite syntax of script that's problem. @ least not in way jslint can detect.
having played live code @ http://ft2.hostei.com/ft.v1/, looks there syntax errors in generated code script puts onclick
attribute in dom. browsers don't job of reporting errors in javascript run via such things (what file , line number of piece of script in onclick
attribute of dynamically inserted element?). why confusing error message in chrome. firefox error message different, , doesn't have useful line number, although firebug show code causes problem.
this snippet of code taken edit
function in inline script block of html:
var sub = document.getelementbyid('submit'); ... sub.setattribute("onclick", "save(\""+file+"\", document.getelementbyid('name').value, document.getelementbyid('text').value");
note sets onclick
attribute of element invalid javascript code:
<input type="submit" id="submit" onclick="save("data/wasup.htm", document.getelementbyid('name').value, document.getelementbyid('text').value">
the js is:
save("data/wasup.htm", document.getelementbyid('name').value, document.getelementbyid('text').value
note missing close paren finish call save
.
as aside, inserting onclick
attributes not modern or clean way of adding event handlers in javascript. why not using dom's addeventlistener
hook function element? if using jquery, simpler still.
- Get link
- X
- Other Apps
Comments
Post a Comment