Passing arguments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Galsaba

    Passing arguments

    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=P1 1
    }
    else
    {
    if (document.form1 .quantity.value >5)
    {
    document.form1. amount.value=P6
    }
    else
    {
    document.form1. amount.value=P1
    }
    }
    }

    Thanks,

    Joe
  • Lasse Reichstein Nielsen

    #2
    Re: Passing arguments

    galsaba@aol.com (Galsaba) writes:
    [color=blue]
    > 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.)[/color]

    Just pass the form:
    function checkForm(myFor m,...) {
    ...
    if (myForm.quantit y.value > 10) ...
    ...
    }

    You will most likely call the function from the form's onsubmit handler,
    and you can just refer to itself as "this" there:
    <form ... onsubmit="retur n checkForm(this, ....);">

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...