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


Groups > comp.lang.javascript > #13335 > unrolled thread

How to Pass variable name to a function

Started byStan Weiss <srweiss@erols.com>
First post2012-04-11 12:26 -0400
Last post2012-04-12 18:54 -0400
Articles 20 on this page of 29 — 12 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-11 12:26 -0400
    Re: How to Pass variable name to a function Andreas Bergmaier <andber93@web.de> - 2012-04-11 19:47 +0200
      Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-11 14:21 -0400
        Re: How to Pass variable name to a function Stefan Weiss <krewecherl@gmail.com> - 2012-04-11 20:53 +0200
          Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-11 15:16 -0400
            Re: How to Pass variable name to a function Gene Wirchenko <genew@ocis.net> - 2012-04-11 15:18 -0700
    Re: How to Pass variable name to a function "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-11 21:20 +0000
    Re: How to Pass variable name to a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-11 23:56 +0200
      Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 00:48 -0400
        Re: How to Pass variable name to a function Andrew Poulos <ap_prog@hotmail.com> - 2012-04-12 15:21 +1000
          Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 02:11 -0400
            Re: How to Pass variable name to a function Andrew Poulos <ap_prog@hotmail.com> - 2012-04-12 18:57 +1000
              Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 09:35 -0400
        Re: How to Pass variable name to a function Stefan Weiss <krewecherl@gmail.com> - 2012-04-12 08:08 +0200
          Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 10:13 -0400
        Re: How to Pass variable name to a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-12 22:47 +0200
          Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 17:04 -0400
            Re: How to Pass variable name to a function Tim Streater <timstreater@greenbee.net> - 2012-04-12 22:17 +0100
            Re: How to Pass variable name to a function Scott Sauyet <scott.sauyet@gmail.com> - 2012-04-13 05:13 -0700
              Re: How to Pass variable name to a function "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-04-13 16:27 +0000
                Re: How to Pass variable name to a function Scott Sauyet <scott.sauyet@gmail.com> - 2012-04-16 04:11 -0700
          Re: How to Pass variable name to a function "Tom de Neef" <tdeneef@qolor.nl> - 2012-04-12 23:34 +0200
            Re: How to Pass variable name to a function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-13 10:03 +0200
            Re: How to Pass variable name to a function Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-04-13 12:03 +0200
              Re: How to Pass variable name to a function Andrew Poulos <ap_prog@hotmail.com> - 2012-04-13 21:35 +1000
              Re: How to Pass variable name to a function Gene Wirchenko <genew@ocis.net> - 2012-04-13 09:00 -0700
    Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 14:03 -0400
    Re: How to Pass variable name to a function Dr J R Stockton <reply1215@merlyn.demon.co.uk.not.invalid> - 2012-04-12 20:06 +0100
      Re: How to Pass variable name to a function Stan Weiss <srweiss@erols.com> - 2012-04-12 18:54 -0400

Page 1 of 2  [1] 2  Next page →


#13335 — How to Pass variable name to a function

FromStan Weiss <srweiss@erols.com>
Date2012-04-11 12:26 -0400
SubjectHow to Pass variable name to a function
Message-ID<4F85B0AE.A1E9FFD8@erols.com>
I have this code in a form which calls the save function.

<TR><TD ALIGN="RIGHT">
<b>Valve Diameter in Millimetres </b>
</TD><TD>
<INPUT TYPE="text" NAME="VD" SIZE=7  onChange="save(stanForm.VD.value,
AInput, 'Valve Diameter')">
</TD></TR>

function save( field, vary, text ) {
     if( isNaN( field ) )
     {
        alert( text + " is not numeric" );
     }
     else
     {
         AInput = eval(field);  // this Works
         vary = eval(field);    // this does not workWorks
     }
}

Can anyone see what I am doing wrong?

Stan

[toc] | [next] | [standalone]


#13336

FromAndreas Bergmaier <andber93@web.de>
Date2012-04-11 19:47 +0200
Message-ID<jm4g3c$t8o$1@news.albasani.net>
In reply to#13335
Stan Weiss schrieb:
> save(stanForm.VD.value, AInput, 'Valve Diameter')"
>
> function save( field, vary, text ) {
>       if( isNaN( field ) )
>       {
>          alert( text + " is not numeric" );
>       }
>       else
>       {
>           AInput = eval(field);  // this Works
>           vary = eval(field);    // this does not workWorks
>       }
> }
>
> Can anyone see what I am doing wrong?

JavaScript does not have call-by-reference. Instead of passing a 
reference to the variable where the result should be stored, you pass 
the actual value of AInput to the function, where it gets the value of 
the local variable "vary". By assigning the result to vary, vary will 
get a new value. AInput is forgotten.

Also, you seem to try to parse a number with eval. Urghh. Use 
parseFloat() instead.

So, your code should be:

function numeric(field, fallback, name) {
     var num = parseFloat(field);
     if (isNaN(num)) {
         alert(name + " is not numeric");
         return fallback;
     } else
         return num;
}
AInput = numeric(stanForm.VD.value, AInput, 'Valve Diameter');

regards,
  Bergi

[toc] | [prev] | [next] | [standalone]


#13337

FromStan Weiss <srweiss@erols.com>
Date2012-04-11 14:21 -0400
Message-ID<4F85CB9C.BB893EA6@erols.com>
In reply to#13336
Andreas Bergmaier wrote:
> 
> Stan Weiss schrieb:
> > save(stanForm.VD.value, AInput, 'Valve Diameter')"
> >
> > function save( field, vary, text ) {
> >       if( isNaN( field ) )
> >       {
> >          alert( text + " is not numeric" );
> >       }
> >       else
> >       {
> >           AInput = eval(field);  // this Works
> >           vary = eval(field);    // this does not workWorks
> >       }
> > }
> >
> > Can anyone see what I am doing wrong?
> 
> JavaScript does not have call-by-reference. Instead of passing a
> reference to the variable where the result should be stored, you pass
> the actual value of AInput to the function, where it gets the value of
> the local variable "vary". By assigning the result to vary, vary will
> get a new value. AInput is forgotten.
> 
> Also, you seem to try to parse a number with eval. Urghh. Use
> parseFloat() instead.
> 
> So, your code should be:
> 
> function numeric(field, fallback, name) {
>      var num = parseFloat(field);
>      if (isNaN(num)) {
>          alert(name + " is not numeric");
>          return fallback;
>      } else
>          return num;
> }
> AInput = numeric(stanForm.VD.value, AInput, 'Valve Diameter');
> 
> regards,
>   Bergi

Thanks for the reply Bergi. It now return the correct value but does not
function the way it did before. If a numeric and alpha are entered it
will take the numeric part and use it. I want it to show any error if
the field is not all numeric.

So I changed
      if (isNaN(num)) {
to
      if( isNaN( field ) )

Thanks again for your help
Best Regards
Stan

[toc] | [prev] | [next] | [standalone]


#13338

FromStefan Weiss <krewecherl@gmail.com>
Date2012-04-11 20:53 +0200
Message-ID<jm4juj$6n1$1@news.albasani.net>
In reply to#13337
On 2012-04-11 20:21, Stan Weiss wrote:
> I want it to show any error if the field is not all numeric.
> 
> So I changed
>       if (isNaN(num)) {
> to
>       if( isNaN( field ) )

I couldn't resist adding something to this thread, considering our
similarity in names... so I'll mention that isNaN() is perhaps not
exactly what you're looking for:

  isNaN("0x123")
  isNaN(".123")
  isNaN("2e6")
  isNaN("Infinity")

These will all evaluate to false, meaning these values would pass your
test. If you want to mandate a specific numeric format, your best bet
would be a regular expression.

For example,

  if (/^[+-]?\d+(?:\.\d+)?$/.test(field)) {
      // correct format
  }

would accept input like "123", "123.123", "+123.123", "-123.123", but
reject the values listed earlier. You may also want to check for
minimum/maximum allowed values.

- stefan

[toc] | [prev] | [next] | [standalone]


#13339

FromStan Weiss <srweiss@erols.com>
Date2012-04-11 15:16 -0400
Message-ID<4F85D89A.4686FE4D@erols.com>
In reply to#13338
Stefan Weiss wrote:
> 
> On 2012-04-11 20:21, Stan Weiss wrote:
> > I want it to show any error if the field is not all numeric.
> >
> > So I changed
> >       if (isNaN(num)) {
> > to
> >       if( isNaN( field ) )
> 
> I couldn't resist adding something to this thread, considering our
> similarity in names... so I'll mention that isNaN() is perhaps not
> exactly what you're looking for:
> 
>   isNaN("0x123")
>   isNaN(".123")
>   isNaN("2e6")
>   isNaN("Infinity")
> 
> These will all evaluate to false, meaning these values would pass your
> test. If you want to mandate a specific numeric format, your best bet
> would be a regular expression.
> 
> For example,
> 
>   if (/^[+-]?\d+(?:\.\d+)?$/.test(field)) {
>       // correct format
>   }
> 
> would accept input like "123", "123.123", "+123.123", "-123.123", but
> reject the values listed earlier. You may also want to check for
> minimum/maximum allowed values.
> 
> - stefan

Thanks Stefan,
while I know it does not catch all errors, I did what to catch things
like 3>3 which should have been 3.3.
Best Regards,
Stan

[toc] | [prev] | [next] | [standalone]


#13343

FromGene Wirchenko <genew@ocis.net>
Date2012-04-11 15:18 -0700
Message-ID<jvvbo7p5hbdk101lqrsr1sqe0poi83e1lc@4ax.com>
In reply to#13339
On Wed, 11 Apr 2012 15:16:42 -0400, Stan Weiss <srweiss@erols.com>
wrote:

>Stefan Weiss wrote:

[snip]

>> I couldn't resist adding something to this thread, considering our
>> similarity in names... so I'll mention that isNaN() is perhaps not
>> exactly what you're looking for:
>> 
>>   isNaN("0x123")
>>   isNaN(".123")
>>   isNaN("2e6")
>>   isNaN("Infinity")
>> 
>> These will all evaluate to false, meaning these values would pass your
>> test. If you want to mandate a specific numeric format, your best bet
>> would be a regular expression.
>> 
>> For example,
>> 
>>   if (/^[+-]?\d+(?:\.\d+)?$/.test(field)) {
>>       // correct format
>>   }
>> 
>> would accept input like "123", "123.123", "+123.123", "-123.123", but
>> reject the values listed earlier. You may also want to check for
>> minimum/maximum allowed values.
>> 
>> - stefan
>
>Thanks Stefan,
>while I know it does not catch all errors, I did what to catch things
>like 3>3 which should have been 3.3.

     You are better off doing it right.  Stefan suggested a regex to
check the format.  If you do not know regexes, you really should read
up about them.  Properly used, they can simplify programming
immensely.  I have been working on a test page, and some time ago, I
was working on checking input for type validity -- exactly what you
are concerned about here -- and found regexes very useful.

     Yes, regexes can easily get into write-only if you do not watch
it, but the example above should be in your repetoire.  (I admit that
I had to read it slowly to be sure and did not already know what
          ?:<string>
does.

     I could do with a complete reference for JavaScript's regex use.
W3Schools's is not complete.  I could use more examples.  Even with
this difficulty, regexes are worth checking out.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#13340

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-04-11 21:20 +0000
Message-ID<XnsA032ED5C429F3eejj99@194.109.133.133>
In reply to#13335
Stan Weiss wrote on 11 apr 2012 in comp.lang.javascript:

> <INPUT NAME="VD" SIZE=7  onChange="save(stanForm.VD.value,
> AInput, 'Valve Diameter')">
> 

for "stanForm.VD.value" use:

"this.value"

and if you cannot use "this", 
because you are calling from another element in the same form use:

"this.form.elements.VD.value"

and if you are calling from outside such form, use:

"document.forms.stanForm.elements.VD.value"

Why?

Because only in IE an element name 
is dangerously misused as an element pointer.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#13341

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-04-11 23:56 +0200
Message-ID<4354243.e4iShcapur@PointedEars.de>
In reply to#13335
Stan Weiss wrote:

> I have this code in a form which calls the save function.
> 
> <TR><TD ALIGN="RIGHT">
> <b>Valve Diameter in Millimetres </b>
> </TD><TD>
> <INPUT TYPE="text" NAME="VD" SIZE=7  onChange="save(stanForm.VD.value,
> AInput, 'Valve Diameter')">
> </TD></TR>
> 
> function save( field, vary, text ) {
>      if( isNaN( field ) )
>      {
>         alert( text + " is not numeric" );
>      }
>      else
>      {
>          AInput = eval(field);  // this Works
>          vary = eval(field);    // this does not workWorks
>      }
> }
> 
> Can anyone see what I am doing wrong?

Yes; it is (at least) the following:

1. Your referencing is proprietary, at best error-prone, needlessly.

     stanForm.VD.value

   is not appropriate referencing (throw that book away).  Assuming that
   your control is descendant of a form element named `stanForm' (which you
   have not showed), an appropriate, standards-compliant, backwards
   compatible and less error-prone referencing would be

     document.forms['stanForm'].elements['VD'].value

   However, as that code appears to be part of the event-handler attribute
   value of the very element that is represented by

     document.forms['stanForm'].elements['VD']

   you can replace that with

     this

   so that the element reads

     <input type="text" name="VD" size="7"
            onchange="save(this.value, AInput, 'Valve Diameter')">

2. You are referring to an identifier before you declare or define it.
   `AInput' is neither declared nor defined before save() is called, so for
   all we know,

     save(this.value, AInput, 'Valve Diameter')

   throws a ReferenceError when evaluating `AInput'.  Check your error
   console.

   It is possible that you have

     var AInput;

   somewhere in your code, or even

     <form name="stanForm" …>
       …
       <input name="AInput" …>
       …
     </form>

   (see also <http://stackoverflow.com/questions/9158238/why-js-function-
    name-conflicts-with-element-id/9160009#9160009>), but then you should
   have posted that.

3. You are using eval().

   Given the aforementioned `forms' and `elements' collections, you do not
   have to use eval() here.  See also <http://jibbering.com/faq/#eval> (in 
   general, *always* read the FAQ of the newsgroup(s) *before* you post to
   them).

4. You are using eval() wrong.

   You are passing for the argument of eval() – `field' – the value of the
   control that calls the very same function.  One could surmise from this
   that you might be trying to implement a calculator.
  
   However, this assumption contradicts your programming where you
   explicitly do not enter the branch with the eval() calls when the string
   value cannot be interpreted as a number, such as a non-trivial equation
   (operand operator operand).

   It is also rather far-fetched to assume that your user would enter
   the names of controls in your form in that input control.

   Therefore, your calls to eval() appear to be completely pointless.  To
   convert a string value to a number value, use the unary `+' operator,
   or the parseInt(…, radix) or parseFloat(…) function calls.

5. "Does not work" is not a problem description.  Read the FAQ on how to
   post when you desire useful answers.

6. You can assign to a function argument, but that does not change the
   value passed for that argument.  There is no call-by-reference, all
   function arguments are values.  (But it does not appear as if you were
   trying to use the assumed assigned value anywhere, so this appears
   to be pointless anyway.)

7. The `change' event occurs on the control when the control loses focus,
   not before.  Do not have your users rely on that, provide a button for
   the computation.  You may perform form validation on change, but you
   should do it in a non-obtrusive way (like adding color).
   Perform any validation that hinders or blocks the user's workflow (like
   an alert message) only on submit; the `form' element has an `onsubmit'
   event-handler attribute for that.

8. Avoid the window.alert() method.  In particular, in recent Gecko-based
   browsers, such an alert message disables the entire viewport of a tab
   until the message is dismissed, and it is very likely to cover the parts
   where the error is.  (IMHO yet another incredibly bad design decision
   in Geckos that we now need to work around – thanks guys :->)

9. Is your markup Valid?  Declare HTML 4.01 Strict or (if necessary) HTML5,
   and replace presentational attributes (like `align') and elements with
   CSS.  <http://validator.w3.org/>

Bottom line: Learn the markup and programming languages before you use an 
API with the programming language, and try something much more simple than 
this first.


PointedEars
-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#13345

FromStan Weiss <srweiss@erols.com>
Date2012-04-12 00:48 -0400
Message-ID<4F865E85.F8DBA81B@erols.com>
In reply to#13341

Thomas 'PointedEars' Lahn wrote:
> 
> Stan Weiss wrote:
> 
> > I have this code in a form which calls the save function.
> >
> > <TR><TD ALIGN="RIGHT">
> > <b>Valve Diameter in Millimetres </b>
> > </TD><TD>
> > <INPUT TYPE="text" NAME="VD" SIZE=7  onChange="save(stanForm.VD.value,
> > AInput, 'Valve Diameter')">
> > </TD></TR>
> >
> > function save( field, vary, text ) {
> >      if( isNaN( field ) )
> >      {
> >         alert( text + " is not numeric" );
> >      }
> >      else
> >      {
> >          AInput = eval(field);  // this Works
> >          vary = eval(field);    // this does not workWorks
> >      }
> > }
> >
> > Can anyone see what I am doing wrong?
> 
> Yes; it is (at least) the following:
> 
> 1. Your referencing is proprietary, at best error-prone, needlessly.
> 
>      stanForm.VD.value
> 
>    is not appropriate referencing (throw that book away).  Assuming that
>    your control is descendant of a form element named `stanForm' (which you
>    have not showed), an appropriate, standards-compliant, backwards
>    compatible and less error-prone referencing would be
> 
>      document.forms['stanForm'].elements['VD'].value
> 
>    However, as that code appears to be part of the event-handler attribute
>    value of the very element that is represented by
> 
>      document.forms['stanForm'].elements['VD']
> 
>    you can replace that with
> 
>      this
> 
>    so that the element reads
> 
>      <input type="text" name="VD" size="7"
>             onchange="save(this.value, AInput, 'Valve Diameter')">
> 
> 2. You are referring to an identifier before you declare or define it.
>    `AInput' is neither declared nor defined before save() is called, so for
>    all we know,
> 
>      save(this.value, AInput, 'Valve Diameter')
> 
>    throws a ReferenceError when evaluating `AInput'.  Check your error
>    console.
> 
>    It is possible that you have
> 
>      var AInput;
> 
>    somewhere in your code, or even
> 
>      <form name="stanForm" …>
>        …
>        <input name="AInput" …>
>        …
>      </form>
> 
>    (see also <http://stackoverflow.com/questions/9158238/why-js-function-
>     name-conflicts-with-element-id/9160009#9160009>), but then you should
>    have posted that.
> 
> 3. You are using eval().
> 
>    Given the aforementioned `forms' and `elements' collections, you do not
>    have to use eval() here.  See also <http://jibbering.com/faq/#eval> (in
>    general, *always* read the FAQ of the newsgroup(s) *before* you post to
>    them).
> 
> 4. You are using eval() wrong.
> 
>    You are passing for the argument of eval() – `field' – the value of the
>    control that calls the very same function.  One could surmise from this
>    that you might be trying to implement a calculator.
> 
>    However, this assumption contradicts your programming where you
>    explicitly do not enter the branch with the eval() calls when the string
>    value cannot be interpreted as a number, such as a non-trivial equation
>    (operand operator operand).
> 
>    It is also rather far-fetched to assume that your user would enter
>    the names of controls in your form in that input control.
> 
>    Therefore, your calls to eval() appear to be completely pointless.  To
>    convert a string value to a number value, use the unary `+' operator,
>    or the parseInt(…, radix) or parseFloat(…) function calls.
> 
> 5. "Does not work" is not a problem description.  Read the FAQ on how to
>    post when you desire useful answers.
> 
> 6. You can assign to a function argument, but that does not change the
>    value passed for that argument.  There is no call-by-reference, all
>    function arguments are values.  (But it does not appear as if you were
>    trying to use the assumed assigned value anywhere, so this appears
>    to be pointless anyway.)
> 
> 7. The `change' event occurs on the control when the control loses focus,
>    not before.  Do not have your users rely on that, provide a button for
>    the computation.  You may perform form validation on change, but you
>    should do it in a non-obtrusive way (like adding color).
>    Perform any validation that hinders or blocks the user's workflow (like
>    an alert message) only on submit; the `form' element has an `onsubmit'
>    event-handler attribute for that.
> 
> 8. Avoid the window.alert() method.  In particular, in recent Gecko-based
>    browsers, such an alert message disables the entire viewport of a tab
>    until the message is dismissed, and it is very likely to cover the parts
>    where the error is.  (IMHO yet another incredibly bad design decision
>    in Geckos that we now need to work around – thanks guys :->)
> 
> 9. Is your markup Valid?  Declare HTML 4.01 Strict or (if necessary) HTML5,
>    and replace presentational attributes (like `align') and elements with
>    CSS.  <http://validator.w3.org/>
> 
> Bottom line: Learn the markup and programming languages before you use an
> API with the programming language, and try something much more simple than
> this first.
> 
> PointedEars
> --
> Anyone who slaps a 'this page is best viewed with Browser X' label on
> a Web page appears to be yearning for the bad old days, before the Web,
> when you had very little chance of reading a document written on another
> computer, another word processor, or another network. -- Tim Berners-Lee

Is this a moderated group?
Are you the group moderator?

I poster enough code to get the answer I needed. While you seem to want
to make all kinds of ASSumptions about things that were not posted.

Thanks for looking

Stan

PS Some old habits - presentational attributes (like `align') go back to
when I used to do this back in 1997. You know what people tell me that
those old scripts still work great.

[toc] | [prev] | [next] | [standalone]


#13346

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-04-12 15:21 +1000
Message-ID<6-qdnWMRH8T1-xvSnZ2dnUVZ_ridnZ2d@westnet.com.au>
In reply to#13345
On 12/04/2012 2:48 PM, Stan Weiss wrote:
>
>
> Thomas 'PointedEars' Lahn wrote:
>>
>> Stan Weiss wrote:
>>
>>> I have this code in a form which calls the save function.
>>>
>>> <TR><TD ALIGN="RIGHT">
>>> <b>Valve Diameter in Millimetres</b>
>>> </TD><TD>
>>> <INPUT TYPE="text" NAME="VD" SIZE=7  onChange="save(stanForm.VD.value,
>>> AInput, 'Valve Diameter')">
>>> </TD></TR>
>>>
>>> function save( field, vary, text ) {
>>>       if( isNaN( field ) )
>>>       {
>>>          alert( text + " is not numeric" );
>>>       }
>>>       else
>>>       {
>>>           AInput = eval(field);  // this Works
>>>           vary = eval(field);    // this does not workWorks
>>>       }
>>> }
>>>
>>> Can anyone see what I am doing wrong?
>>
>> Yes; it is (at least) the following:
>>
>> 1. Your referencing is proprietary, at best error-prone, needlessly.
>>
>>       stanForm.VD.value
>>
>>     is not appropriate referencing (throw that book away).  Assuming that
>>     your control is descendant of a form element named `stanForm' (which you
>>     have not showed), an appropriate, standards-compliant, backwards
>>     compatible and less error-prone referencing would be
>>
>>       document.forms['stanForm'].elements['VD'].value
>>
>>     However, as that code appears to be part of the event-handler attribute
>>     value of the very element that is represented by
>>
>>       document.forms['stanForm'].elements['VD']
>>
>>     you can replace that with
>>
>>       this
>>
>>     so that the element reads
>>
>>       <input type="text" name="VD" size="7"
>>              onchange="save(this.value, AInput, 'Valve Diameter')">
>>
>> 2. You are referring to an identifier before you declare or define it.
>>     `AInput' is neither declared nor defined before save() is called, so for
>>     all we know,
>>
>>       save(this.value, AInput, 'Valve Diameter')
>>
>>     throws a ReferenceError when evaluating `AInput'.  Check your error
>>     console.
>>
>>     It is possible that you have
>>
>>       var AInput;
>>
>>     somewhere in your code, or even
>>
>>       <form name="stanForm" …>
>>         …
>>         <input name="AInput" …>
>>         …
>>       </form>
>>
>>     (see also<http://stackoverflow.com/questions/9158238/why-js-function-
>>      name-conflicts-with-element-id/9160009#9160009>), but then you should
>>     have posted that.
>>
>> 3. You are using eval().
>>
>>     Given the aforementioned `forms' and `elements' collections, you do not
>>     have to use eval() here.  See also<http://jibbering.com/faq/#eval>  (in
>>     general, *always* read the FAQ of the newsgroup(s) *before* you post to
>>     them).
>>
>> 4. You are using eval() wrong.
>>
>>     You are passing for the argument of eval() – `field' – the value of the
>>     control that calls the very same function.  One could surmise from this
>>     that you might be trying to implement a calculator.
>>
>>     However, this assumption contradicts your programming where you
>>     explicitly do not enter the branch with the eval() calls when the string
>>     value cannot be interpreted as a number, such as a non-trivial equation
>>     (operand operator operand).
>>
>>     It is also rather far-fetched to assume that your user would enter
>>     the names of controls in your form in that input control.
>>
>>     Therefore, your calls to eval() appear to be completely pointless.  To
>>     convert a string value to a number value, use the unary `+' operator,
>>     or the parseInt(…, radix) or parseFloat(…) function calls.
>>
>> 5. "Does not work" is not a problem description.  Read the FAQ on how to
>>     post when you desire useful answers.
>>
>> 6. You can assign to a function argument, but that does not change the
>>     value passed for that argument.  There is no call-by-reference, all
>>     function arguments are values.  (But it does not appear as if you were
>>     trying to use the assumed assigned value anywhere, so this appears
>>     to be pointless anyway.)
>>
>> 7. The `change' event occurs on the control when the control loses focus,
>>     not before.  Do not have your users rely on that, provide a button for
>>     the computation.  You may perform form validation on change, but you
>>     should do it in a non-obtrusive way (like adding color).
>>     Perform any validation that hinders or blocks the user's workflow (like
>>     an alert message) only on submit; the `form' element has an `onsubmit'
>>     event-handler attribute for that.
>>
>> 8. Avoid the window.alert() method.  In particular, in recent Gecko-based
>>     browsers, such an alert message disables the entire viewport of a tab
>>     until the message is dismissed, and it is very likely to cover the parts
>>     where the error is.  (IMHO yet another incredibly bad design decision
>>     in Geckos that we now need to work around – thanks guys :->)

PE, I don't understand, isn't that the point of an alert?

>> 9. Is your markup Valid?  Declare HTML 4.01 Strict or (if necessary) HTML5,
>>     and replace presentational attributes (like `align') and elements with
>>     CSS.<http://validator.w3.org/>
>>
>> Bottom line: Learn the markup and programming languages before you use an
>> API with the programming language, and try something much more simple than
>> this first.
>>
>> PointedEars
>> --
>> Anyone who slaps a 'this page is best viewed with Browser X' label on
>> a Web page appears to be yearning for the bad old days, before the Web,
>> when you had very little chance of reading a document written on another
>> computer, another word processor, or another network. -- Tim Berners-Lee
>
> Is this a moderated group?

I don't think so.

> Are you the group moderator?

See answer to previous question.

> I poster enough code to get the answer I needed. While you seem to want
> to make all kinds of ASSumptions about things that were not posted.

You're upset that someone took the time to point out mistakes you have made?

> Thanks for looking
>
> Stan
>
> PS Some old habits - presentational attributes (like `align') go back to
> when I used to do this back in 1997. You know what people tell me that

That you have been using 'align' for 15 years does not make it the best 
thing to do today.

> those old scripts still work great.

As if (that is, I doubt it).

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#13348

FromStan Weiss <srweiss@erols.com>
Date2012-04-12 02:11 -0400
Message-ID<4F86722C.B079573F@erols.com>
In reply to#13346
Andrew Poulos wrote:
> 
> On 12/04/2012 2:48 PM, Stan Weiss wrote:
> > Is this a moderated group?
> 
> I don't think so.
> 
> > Are you the group moderator?
> 
> See answer to previous question.
> 
> > I poster enough code to get the answer I needed. While you seem to want
> > to make all kinds of ASSumptions about things that were not posted.
> 
> You're upset that someone took the time to point out mistakes you have made?
> 
> > Thanks for looking
> >
> > Stan
> >
> > PS Some old habits - presentational attributes (like `align') go back to
> > when I used to do this back in 1997. You know what people tell me that
> 
> That you have been using 'align' for 15 years does not make it the best
> thing to do today.
> 
> > those old scripts still work great.
> 
> As if (that is, I doubt it).
> 
> Andrew Poulos

Andrew,
I had hours before gotten a answer to my question. PE then comes along
an points out things that are wrong in my code. Not a problem. I only
showed code snippets so making ASSumptions about things that were not
posted like 2# above does what? If there were any messages in the error
console I would have fixed them before asking for help. Also what does
using CSS have to do with javaScript?

Stan

[toc] | [prev] | [next] | [standalone]


#13349

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-04-12 18:57 +1000
Message-ID<2PydnffUHOCHBBvSnZ2dnUVZ_t6dnZ2d@westnet.com.au>
In reply to#13348
On 12/04/2012 4:11 PM, Stan Weiss wrote:
> Andrew Poulos wrote:
>>
>> On 12/04/2012 2:48 PM, Stan Weiss wrote:
>>> Is this a moderated group?
>>
>> I don't think so.
>>
>>> Are you the group moderator?
>>
>> See answer to previous question.
>>
>>> I poster enough code to get the answer I needed. While you seem to want
>>> to make all kinds of ASSumptions about things that were not posted.
>>
>> You're upset that someone took the time to point out mistakes you have made?
>>
>>> Thanks for looking
>>>
>>> Stan
>>>
>>> PS Some old habits - presentational attributes (like `align') go back to
>>> when I used to do this back in 1997. You know what people tell me that
>>
>> That you have been using 'align' for 15 years does not make it the best
>> thing to do today.
>>
>>> those old scripts still work great.
>>
>> As if (that is, I doubt it).
>>
>> Andrew Poulos
>
> Andrew,
> I had hours before gotten a answer to my question. PE then comes along

You think "hours" waiting for a reply on usenet is a long time? Perhaps 
you're mistaking this NG for a help desk.

> an points out things that are wrong in my code. Not a problem. I only
> showed code snippets so making ASSumptions about things that were not

Yes I got your pun the first time.

> posted like 2# above does what? If there were any messages in the error

People can only go on what you post. If you thought PE's comments wrong 
you could've replied "yes you make a valid point but in my case it 
doesn't apply as there's code that I've not shown which does 
declare/define 'AInput'".

> console I would have fixed them before asking for help. Also what does

Really, and how would anyone know that? You being so against anyone 
making assumptions.

> using CSS have to do with JavaScript?

If you have to ask then perhaps you need to study a bit more.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#13351

FromStan Weiss <srweiss@erols.com>
Date2012-04-12 09:35 -0400
Message-ID<4F86DA18.7F4A84E@erols.com>
In reply to#13349
Andrew Poulos wrote:
> 
> On 12/04/2012 4:11 PM, Stan Weiss wrote:
> > Andrew Poulos wrote:
> >>
> >> On 12/04/2012 2:48 PM, Stan Weiss wrote:
> >>> Is this a moderated group?
> >>
> >> I don't think so.
> >>
> >>> Are you the group moderator?
> >>
> >> See answer to previous question.
> >>
> >>> I poster enough code to get the answer I needed. While you seem to want
> >>> to make all kinds of ASSumptions about things that were not posted.
> >>
> >> You're upset that someone took the time to point out mistakes you have made?
> >>
> >>> Thanks for looking
> >>>
> >>> Stan
> >>>
> >>> PS Some old habits - presentational attributes (like `align') go back to
> >>> when I used to do this back in 1997. You know what people tell me that
> >>
> >> That you have been using 'align' for 15 years does not make it the best
> >> thing to do today.
> >>
> >>> those old scripts still work great.
> >>
> >> As if (that is, I doubt it).
> >>
> >> Andrew Poulos
> >
> > Andrew,
> > I had hours before gotten a answer to my question. PE then comes along
> 
> You think "hours" waiting for a reply on usenet is a long time? Perhaps
> you're mistaking this NG for a help desk.

Where did I say anything about >>> "hours" waiting for a reply <<<< I
said hours after I had gotten an answer. I understand how NGs work. I
have been using them for over 15 year and before that FIDONET.

> 
> > an points out things that are wrong in my code. Not a problem. I only
> > showed code snippets so making ASSumptions about things that were not
> 
> Yes I got your pun the first time.
> 
> > posted like 2# above does what? If there were any messages in the error
> 
> People can only go on what you post. If you thought PE's comments wrong
> you could've replied "yes you make a valid point but in my case it
> doesn't apply as there's code that I've not shown which does
> declare/define 'AInput'".
> 
> > console I would have fixed them before asking for help. Also what does
> 
> Really, and how would anyone know that? You being so against anyone
> making assumptions.
> 
> > using CSS have to do with JavaScript?
> 
> If you have to ask then perhaps you need to study a bit more.

Explain to me how CSS played any part in solving my problem. This is
html.
>>> <TD ALIGN="RIGHT"> <<< - It maybe "Old School" but it still works.

> 
> Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#13347

FromStefan Weiss <krewecherl@gmail.com>
Date2012-04-12 08:08 +0200
Message-ID<jm5rh8$8s7$1@news.albasani.net>
In reply to#13345
On 2012-04-12 06:48, Stan Weiss wrote:
> Thomas 'PointedEars' Lahn wrote:
>> 1. Your referencing is proprietary, at best error-prone, needlessly.
..
>> 2. You are referring to an identifier before you declare or define it.
..
>> 3. You are using eval().
..
>> 4. You are using eval() wrong.
..
>> 5. "Does not work" is not a problem description.
..
>> 6. You can assign to a function argument, but that does not change the
>>    value passed for that argument.
..
>> 7. The `change' event occurs on the control when the control loses focus,
..
>> 8. Avoid the window.alert() method.
..
>> 9. Is your markup Valid?

> Is this a moderated group?
> Are you the group moderator?

No and no.

> I poster enough code to get the answer I needed. While you seem to want
> to make all kinds of ASSumptions about things that were not posted.

That was actually one of Thomas's more useful replies. Nobody here would
have been surprised if he had answered your question "Can anyone see
what I am doing wrong?" with "Yes" and no further comment. At least you
didn't give him a chance to say "There is no javascript".

Manners aside, most of his points are valid. Especially: don't use
eval() unless you know exactly what you are doing; do validate the
document before you begin debugging your scripts; stanForm.VD is not a
good way to reference a form element; and don't expect an assignment to
a function parameter to be visible outside the function. These points
really are important for you to understand. The rest will come with time
and practice.

- stefan

[toc] | [prev] | [next] | [standalone]


#13352

FromStan Weiss <srweiss@erols.com>
Date2012-04-12 10:13 -0400
Message-ID<4F86E323.AE36EFB4@erols.com>
In reply to#13347
Stefan Weiss wrote:
> 
> On 2012-04-12 06:48, Stan Weiss wrote:
> > Thomas 'PointedEars' Lahn wrote:
> >> 1. Your referencing is proprietary, at best error-prone, needlessly.
> ..
> >> 2. You are referring to an identifier before you declare or define it.
> ..
> >> 3. You are using eval().
> ..
> >> 4. You are using eval() wrong.
> ..
> >> 5. "Does not work" is not a problem description.
> ..
> >> 6. You can assign to a function argument, but that does not change the
> >>    value passed for that argument.
> ..
> >> 7. The `change' event occurs on the control when the control loses focus,
> ..
> >> 8. Avoid the window.alert() method.
> ..
> >> 9. Is your markup Valid?
> 
> > Is this a moderated group?
> > Are you the group moderator?
> 
> No and no.
> 
> > I poster enough code to get the answer I needed. While you seem to want
> > to make all kinds of ASSumptions about things that were not posted.
> 
> That was actually one of Thomas's more useful replies. Nobody here would
> have been surprised if he had answered your question "Can anyone see
> what I am doing wrong?" with "Yes" and no further comment. At least you
> didn't give him a chance to say "There is no javascript".
> 
> Manners aside, most of his points are valid. Especially: don't use
> eval() unless you know exactly what you are doing; do validate the
> document before you begin debugging your scripts; stanForm.VD is not a
> good way to reference a form element; and don't expect an assignment to
> a function parameter to be visible outside the function. These points
> really are important for you to understand. The rest will come with time
> and practice.
> 
> - stefan

Thanks Stefan for the help.

Stan

[toc] | [prev] | [next] | [standalone]


#13356

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-04-12 22:47 +0200
Message-ID<1399313.AFRqVoOGUt@PointedEars.de>
In reply to#13345
Stan Weiss wrote:

> Thomas 'PointedEars' Lahn wrote:
>> [Full quote]
> 
> Is this a moderated group?
> Are you the group moderator?
> 
> I poster enough code to get the answer I needed. While you seem to want
> to make all kinds of ASSumptions about things that were not posted.
> 
> Thanks for looking
> 
> Stan
> 
> PS Some old habits - presentational attributes (like `align') go back to
> when I used to do this back in 1997. You know what people tell me that
> those old scripts still work great.

Could someone please remind me that I never again invest free time into 
replying to such a posting?  TIA.

*PLONK*

[toc] | [prev] | [next] | [standalone]


#13357

FromStan Weiss <srweiss@erols.com>
Date2012-04-12 17:04 -0400
Message-ID<4F87435C.5F694446@erols.com>
In reply to#13356
Thomas 'PointedEars' Lahn wrote:
> 
> Stan Weiss wrote:
> 
> > Thomas 'PointedEars' Lahn wrote:
> >> [Full quote]
> >
> > Is this a moderated group?
> > Are you the group moderator?
> >
> > I poster enough code to get the answer I needed. While you seem to want
> > to make all kinds of ASSumptions about things that were not posted.
> >
> > Thanks for looking
> >
> > Stan
> >
> > PS Some old habits - presentational attributes (like `align') go back to
> > when I used to do this back in 1997. You know what people tell me that
> > those old scripts still work great.
> 
> Could someone please remind me that I never again invest free time into
> replying to such a posting?  TIA.
> 
> *PLONK*

Thomas,
I am sure you will continue to reply to these messages. Because I
believe it has nothing to do with helping other but rather you wanting
to show everybody how smart you are. <lol>

Stan

[toc] | [prev] | [next] | [standalone]


#13358

FromTim Streater <timstreater@greenbee.net>
Date2012-04-12 22:17 +0100
Message-ID<timstreater-E0A82C.22171212042012@news.individual.net>
In reply to#13357
In article <4F87435C.5F694446@erols.com>,
 Stan Weiss <srweiss@erols.com> wrote:

> Thomas 'PointedEars' Lahn wrote:
> > 
> > Stan Weiss wrote:
> > 
> > > Thomas 'PointedEars' Lahn wrote:
> > >> [Full quote]
> > >
> > > Is this a moderated group?
> > > Are you the group moderator?
> > >
> > > I poster enough code to get the answer I needed. While you seem to want
> > > to make all kinds of ASSumptions about things that were not posted.
> > >
> > > Thanks for looking
> > >
> > > Stan
> > >
> > > PS Some old habits - presentational attributes (like `align') go back to
> > > when I used to do this back in 1997. You know what people tell me that
> > > those old scripts still work great.
> > 
> > Could someone please remind me that I never again invest free time into
> > replying to such a posting?  TIA.
> > 
> > *PLONK*
> 
> Thomas,
> I am sure you will continue to reply to these messages. Because I
> believe it has nothing to do with helping other but rather you wanting
> to show everybody how smart you are. <lol>

Stan is right, Pointyhead. Why don't you plonk everybody, that way you 
will never see any posts from mere mortals.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#13366

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-04-13 05:13 -0700
Message-ID<0a617a96-55cd-4f19-b722-42ae697f5ade@h4g2000yqj.googlegroups.com>
In reply to#13357
Stan Weiss wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Stan Weiss wrote:
>>> Thomas 'PointedEars' Lahn wrote:

[ a very detailed and helpful response ]

>>> Is this a moderated group?
>>> Are you the group moderator?
>
>>> I poster enough code to get the answer I needed. While you seem to want
>>> to make all kinds of ASSumptions about things that were not posted.
[ ... ]

>> Could someone please remind me that I never again invest free time into
>> replying to such a posting?  TIA.

> I am sure you will continue to reply to these messages. Because I
> believe it has nothing to do with helping other but rather you wanting
> to show everybody how smart you are. <lol>

Thomas will, I hope, continue to post, even responses to requests for
help.

It may not feel like it to you, but that was Thomas being more helpful
than usual.  This is not some paid help forum.  It is a newsgroup used
to discuss Javascript.  There are plenty of times when regulars here
feel like offering advice to those seeking it, but that is not the
main purpose of the group.  Thomas offered nine detailed points, all
of which were on-topic, well-stated, and non-argumentative, and a
summary which was perhaps condescending but not terribly insulting.
It's hard to be more helpful than that.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#13368

From"Evertjan." <exjxw.hannivoort@interxnl.net>
Date2012-04-13 16:27 +0000
Message-ID<XnsA034BBAFF7132eejj99@194.109.133.133>
In reply to#13366
Scott Sauyet wrote on 13 apr 2012 in comp.lang.javascript:

> Thomas will, I hope, continue to post, even responses to requests for
> help.
> 
> It may not feel like it to you, but that was Thomas being more helpful
> than usual.  This is not some paid help forum.  It is a newsgroup used
> to discuss Javascript.  There are plenty of times when regulars here
> feel like offering advice to those seeking it, but that is not the
> main purpose of the group.  Thomas offered nine detailed points, all
> of which were on-topic, well-stated, and non-argumentative, and a
> summary which was perhaps condescending but not terribly insulting.
> It's hard to be more helpful than that.

I agree with all this, except the "non-argumentative".

What do you mean by "non-argumentative", my dear Watson?

===

ar·gu·ment [ahr-gyuh-muhnt] noun
1.
an oral disagreement; verbal opposition; contention; altercation: a 
violent argument.
2.
a discussion involving differing points of view; debate: They were deeply 
involved in an argument about inflation.
3.
a process of reasoning; series of reasons: I couldn't follow his 
argument.
4.
a statement, reason, or fact for or against a point: This is a strong 
argument in favor of her theory.
5.
an address or composition intended to convince or persuade; persuasive 
discourse.
6.
subject matter; theme: The central argument of his paper was presented 
clearly.
7.
an abstract or summary of the major points in a work of prose or poetry, 
or of sections of such a work.
8.
Mathematics .
a.
an independent variable of a function.
b.
Also called amplitude. the angle made by a given vector with the 
reference axis.
c.
the angle corresponding to a point representing a given complex number in 
polar coordinates. Compare principal argument.
9.
Computers . a variable in a program, to which a value will be assigned 
when the program is run: often given in parentheses following a function 
name and used to calculate the function.
10.
Obsolete .
a.
evidence or proof.
b.
a matter of contention.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.javascript


csiph-web