Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > JavaScript - Passing Arguments

Reply
Thread Tools

JavaScript - Passing Arguments

 
 
Galsaba
Guest
Posts: n/a
 
      04-04-2004
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
}
}
}

 
Reply With Quote
 
 
 
 
Eric Bohlman
Guest
Posts: n/a
 
      04-04-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
 
 
 
Galsaba
Guest
Posts: n/a
 
      04-04-2004
Thanks!
It worked for me!!

galsaba
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      04-05-2004
Eric Bohlman wrote:
> (E-Mail Removed) (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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
functions and arguments.length; passing unknown number of arguments oldyork90 Javascript 10 09-27-2008 03:05 AM
Passing multiple arguments to the client-side JavaScript function in AJAX Nathan Sokalski ASP .Net Building Controls 4 11-20-2006 06:27 PM
Passing multiple arguments to the client-side JavaScript function in AJAX Nathan Sokalski ASP .Net 4 11-20-2006 06:27 PM
Difference between default arguments and keyword arguments Edward Diener Python 14 04-05-2004 11:26 PM
Passing Arguments (JavaScript) Galsaba HTML 0 04-04-2004 06:16 PM



Advertisments