Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Dr J R Stockton Newsgroups: comp.lang.javascript Subject: Re: What is wrong with this code?its not working Date: Wed, 26 Oct 2011 22:21:21 +0100 Organization: Home Lines: 59 Message-ID: References: <55a344ce-8a2b-494a-bfe8-fadd3a5e2e08@h30g2000pro.googlegroups.com> <4ea616f4$0$28474$a8266bb1@newsreader.readnews.com> Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="UwYDIHu13GPq28RciNoAJA"; logging-data="32753"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18spcDGRGNRgHvP/oRlUhenTIlc7GflL5c=" User-Agent: Turnpike/6.05-S () Cancel-Lock: sha1:gDSkATzRfvow8ebpaP9+hNNMwHg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:7709 In comp.lang.javascript message <4ea616f4$0$28474$a8266bb1@newsreader.re adnews.com>, Tue, 25 Oct 2011 01:55:00, Denis McMahon posted: >On Sat, 22 Oct 2011 23:33:35 -0700, Mclaren Fan wrote: > >> too much code > >I think Lasse has nailed your problem. You have use the same identifier >("add") for an element name and a function name, and that's confusing the >browser. The code is horribly repetitive. There seem to be several near- identical functions, such as function put3(form) { if (form.out2.type=="text") { var val=form.out2.value; var newval=val+3; form.out2.value=newval; } else { var val=form.out.value; var newval=val+3; form.out.value=newval; } } The "3" should be an argument, saving several functions : function putN(form, N) { if (form.out2.type=="text") { var val=form.out2.value; var newval=val+N; form.out2.value=newval; } else { var val=form.out.value; var newval=val+N; form.out.value=newval; } } and it could be (beware mis-readings and mis-writings) function putN(form, N) { var S = form.out2.type=="text" ? "out2" : "out" form[S].value += N } Having bow looked at the form : the button names may not be needed, and if the "put" calls have an argument of just "this" the "put" routine can both read the button value and locate the form. All untested. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME. Web - FAQqish topics, acronyms and links; Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc. No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.