JavaScript - Passing Arguments

Discussion in 'HTML' started by Galsaba, Apr 4, 2004.

  1. Galsaba

    Galsaba Guest

    I want to use checkForm function for 10 forms I have.
    form1, form2....., form10.
    How can I pass argument to
    ....
    if (document.formX.quantity.value>10)
    ....
    (formX will be form1 or form2, ...or form10 etc.)

    function checkForm(P1,P6,P11)
    {
    if (document.form1.quantity.value>10)
    {
    document.form1.amount.value=P11
    }
    else
    {
    if (document.form1.quantity.value>5)
    {
    document.form1.amount.value=P6
    }
    else
    {
    document.form1.amount.value=P1
    }
    }
    }
     
    Galsaba, Apr 4, 2004
    #1
    1. Advertising

  2. Galsaba

    Eric Bohlman Guest

    (Galsaba) wrote in news:20040404091659.16093.00000635@mb-
    m04.aol.com:

    > I want to use checkForm function for 10 forms I have.
    > form1, form2....., form10.
    > How can I pass argument to
    > ...
    > if (document.formX.quantity.value>10)
    > ...
    > (formX will be form1 or form2, ...or form10 etc.)


    Use the "collection" syntax:

    if (document.forms['formX'].quantity.value>10)

    The index to document.forms[] is a string, so you can build it up by
    concatenation:

    function checkForm(n,P1,P6,P11)
    {var whichform=document.forms['form'+n];
    if (whichform.quantity.value>10)
    {whichform.amount.value=P11
    }
    etc.
     
    Eric Bohlman, Apr 4, 2004
    #2
    1. Advertising

  3. Galsaba

    Galsaba Guest

    Thanks!
    It worked for me!!

    galsaba
     
    Galsaba, Apr 4, 2004
    #3
  4. Eric Bohlman wrote:
    > (Galsaba) wrote:

    <snip>
    >> if (document.formX.quantity.value>10)
    >> ...
    >> (formX will be form1 or form2, ...or form10 etc.)

    >
    > Use the "collection" syntax:
    >
    > if (document.forms['formX'].quantity.value>10)

    <snip>

    It is misleading to refer to this a '"collection" syntax', as javascript
    has no notion of "collection", that is a host environment (usually
    browser) construct. While the syntax is categorised by ECMA 262 as a
    "bracket notation property accessor", and, as such, is a core language
    feature; a direct alternative to dot notation property accessors that
    apply in any, and all, named property resolution contexts in javascript.

    Richard.
     
    Richard Cornford, Apr 5, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Galsaba

    Passing Arguments (JavaScript)

    Galsaba, Apr 4, 2004, in forum: HTML
    Replies:
    0
    Views:
    380
    Galsaba
    Apr 4, 2004
  2. Edward Diener
    Replies:
    14
    Views:
    4,972
    Josiah Carlson
    Apr 6, 2004
  3. Nathan Sokalski
    Replies:
    4
    Views:
    1,185
    Steve C. Orr [MVP, MCSD]
    Nov 20, 2006
  4. Nathan Sokalski

    Passing multiple arguments to the client-side JavaScript function in AJAX

    Nathan Sokalski, Nov 20, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    246
    Steve C. Orr [MVP, MCSD]
    Nov 20, 2006
  5. oldyork90
    Replies:
    10
    Views:
    348
    Jorge
    Sep 27, 2008
Loading...

Share This Page