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


Groups > comp.lang.javascript > #7709

Re: What is wrong with this code?its not working

From Dr J R Stockton <reply1143@merlyn.demon.co.uk>
Newsgroups comp.lang.javascript
Subject Re: What is wrong with this code?its not working
Date 2011-10-26 22:21 +0100
Organization Home
Message-ID <PQAs9OURnHqOFwC+@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <55a344ce-8a2b-494a-bfe8-fadd3a5e2e08@h30g2000pro.googlegroups.com> <4ea616f4$0$28474$a8266bb1@newsreader.readnews.com>

Show all headers | View raw


In comp.lang.javascript message <4ea616f4$0$28474$a8266bb1@newsreader.re
adnews.com>, Tue, 25 Oct 2011 01:55:00, Denis McMahon
<denismfmcmahon@gmail.com> 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  <http://www.merlyn.demon.co.uk/> - 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.

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


Thread

What is wrong with this code?its not working Mclaren Fan <himanshu1495@gmail.com> - 2011-10-22 23:33 -0700
  Re: Please google for a FAQ on asking questions Andreas Bergmaier <andber93@web.de> - 2011-10-23 10:52 +0200
  Re: What is wrong with this code?its not working Lasse Reichstein Nielsen <lrn.unread@gmail.com> - 2011-10-23 11:46 +0200
  Re: What is wrong with this code?its not working John G Harris <john@nospam.demon.co.uk> - 2011-10-23 11:25 +0100
    Re: What is wrong with this code?its not working Dr J R Stockton <reply1143@merlyn.demon.co.uk> - 2011-10-24 20:05 +0100
  Re: What is wrong with this code?its not working Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-25 01:55 +0000
    Re: What is wrong with this code?its not working Dr J R Stockton <reply1143@merlyn.demon.co.uk> - 2011-10-26 22:21 +0100
      Re: What is wrong with this code?its not working Denis McMahon <denismfmcmahon@gmail.com> - 2011-10-26 23:34 +0000
        Re: What is wrong with this code?its not working Mclaren Fan <himanshu1495@gmail.com> - 2011-10-27 01:26 -0700
          Re: What is wrong with this code?its not working sparky <simonp99@googlemail.com> - 2011-10-27 09:46 -0700

csiph-web