i have image supposed run function when clicking it, strange reason getting error "unexpected token }". here code: html:
<img src='images/buildings/house_3.png' onclick='selectbuilding('house');'>
javascript:
function selectbuilding(whichbuilding) { building = whichbuilding; buildingselected = 1; if (building == "house") { document.getelementbyid('maparea').innerhtml="<form method='post'><h2>base</h2><input id='button' type='button' name='button' onclick='myfunction();' value='close'/><input id='button' type='button' name='button' onclick='checkelement();' value='upgrade base'/></form>"; } if (building == "wood") { document.getelementbyid('maparea').innerhtml="<form method='post'><h2>wood</h2><input id='button' type='button' name='button' onclick='myfunction();' value='close'/><input id='button' type='button' name='button' onclick='checkelement();' value='upgrade wood'/></form>"; } else { document.getelementbyid('selectbuilding').innerhtml="<img src='images/buildings/" + building + "_3.png'>"; } }
please help!
look @ html, attribute value. how should parser know attribute value ends @ fourth '
, not second? can't.
the code wrote equivalent to
<img onclick='selectbuilding(' />
which internally creates like
function handler(event) { selectbuilding( }
which not valid javascript. use double quotes function argument or attribute value.
Comments
Post a Comment