Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!217.73.144.45.MISMATCH!feeder2.ecngs.de!ecngs!feeder.ecngs.de!news.osn.de!diablo2.news.osn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!feed118.news.tele.dk!not-for-mail Newsgroups: comp.lang.javascript Subject: Re: What is wrong with this code?its not working References: <55a344ce-8a2b-494a-bfe8-fadd3a5e2e08@h30g2000pro.googlegroups.com> From: Lasse Reichstein Nielsen Date: Sun, 23 Oct 2011 11:46:29 +0200 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Rational FORTRAN, windows-nt) Cancel-Lock: sha1:y6eRx0J9XsUWW/GqLdunaMUUNx4= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 74 Organization: TDC Totalloesninger NNTP-Posting-Host: 87.57.52.80 X-Trace: 1319363190 dtext01.news.tele.dk 286 87.57.52.80:65324 X-Complaints-To: abuse@post.tele.dk Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7634 Mclaren Fan writes: > >
> onclick="put(this.form, '0');" ... > onClick="makevis(this.form)"> > onClick="add(this.form)"> This call top "add" doesn't see the global add function. Instead the "add" variable resolves to the "add" button just above. The intrinsic event handlers (javascript written directly in the onclick attribute) is executed in a scope that contains, amongst other elements, the current form element (like if you had written "with(form) { ...my handler ...}"). In the debugger in Chrome (start, e.g., by pressing Ctrl-Shift-J)), I got the error: "Uncaught TypeError: object is not a function" at the line containing 'onClick="add(this.form)">'. That should be a hint, since only one function call is performed there. Then you can add an "alert(add)" to see what object "add" resolves to, and you'll see that it's an HTML input element. You got lucky this time, but in the fututre, if you need someone to help you debug a problem, you need to tell us: - What you did (the code is good, but also say which keys or buttons to press to reproduce the problem, if it's not immediately obvious). Otherwise we'll have to guess how to reproduce it. - What actually happens. It might not reproduce the same way in other browsers, and someone who doesn't see the problem, but doesn't know so, is wasting his time. - What you expects to happen. Otherwise we'll have to guess what you want in order to find a fix. Anything that requires people helping you to guess (with the chance of guessing wrong) or to ask you for more information, or otherwise spend time not directly related to finding and fixing the problem, increases the chance that they won't bother. I.e., in order to get the most help, it's best to decrease the effort needed to help. /L 'Tell us what we need to reproduce, recognize and repair the problem' -- Lasse Reichstein Holst Nielsen 'Javascript frameworks is a disruptive technology'