SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Montreal
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript: strange error

    Here is the JavaScript used (I picked up it here) with a form

    function calcul(ind)
    {
    res[ind].value=Number(pri[ind].value)*Number(qte[ind].value);
    total.value=0;
    for (var n=0;n<res.length;n++)
    {total.value=Number(total.value)+Number(res[n].value); }
    The program works apparently fine as long as I take off the 1rst line of the form: <form action =... >. When I leave in in place, I get the following error.:'re' is undefined...code 0.

    I can't understand where is the problem.

    Any solution?

    P.S. Can send the entire code as attachment file is necessary

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get the following error.:'re' is undefined...code 0.
    There is no variable 're', and you might want to indicate what line the error was on. It never ceases to amaze me how many people post without that information.

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Montreal
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Apologize!

    You are right.
    I reformulate my my problems and post the entire code.

    What I need:
    1) To make an order, the user write in the correct textbox(es) the quantity need. Al the other calculation are automatically done;
    2) a snippet to link to paypal;

    What I do can be seen in the following code;

    What is wrong;
    1) Don't know how to calculate the total quantity ordered, necessary to get the total shipping cost;
    2) All works relatively fine without the opening line of the form (<form action=...)When this opening line is uncommented, I get the error: line 10 char 1 error: 'res' is undefined.

    What I don't understand is what I don't get this error when the form is disabled?

    Following the code
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"/>

    <HTML>
    <HEAD>
    <TITLE>Untitled</TITLE>
    <META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ ME"/>
    <script type="text/javascript"/>
    function calcul(ind)
    {
    res[ind].value=Number(pri[ind].value)*Number(qte[ind].value);
    total.value=0;
    for (var n=0;n<res.length;n++)
    {total.value=Number(total.value)+Number(res[n].value); }

    // Gross amount
    var grossamount="grossamont";
    grossamount.value=0;
    //grossamount.value=Number(total.value)+++;

    // TPS Canada seulement
    tpscan.value=0;
    {(tpscan.value=Number(total.value)*Number(0.07));}

    canexpd.value=0;
    {canexpd.value=Number(6.50)+(Number(2.50)*(Number(qte[ind].value)-Number(1)));}

    usexpd.value=0;
    {usexpd.value=Number(8.50)+(Number(3.50)*(Number(qte[ind].value)-Number(1)));}

    autrexpd.value=0;
    {autrexpd.value=Number(9.75)+(Number(4.75)*(Number(qte[ind].value)-Number(1)));}
    }
    </script>
    </HEAD>

    <BODY>

    <!-- Livres 1
    <FORM ACTION="mailto:webmaster@biblio-select.com"/> -->
    <!-- Item definitions -->
    <input type="text" name="price" size="3" readonly value="Price"/>
    <input type="text" name="qty" size="3" readonly value="Qty"/>
    <input type="text" name="amount" size="3" readonly value="Gross"/>
    <BR>

    <!-- Livres 1 -->
    <input type="text" name="pri" size="3" readonly value="31.95"/>
    <input type="text" name="qte" size="3" onblur="calcul(0);"/>
    <input type="text" name="res" size="3" readonly value=""/>&nbsp;<B>&nbsp;&nbsp;Title 1</B>
    <BR>
    <!-- Livre # 2 -->
    <input type="text" name="pri" size="3" readonly value="26.95"/>
    <input type="text" name="qte" size="3" onblur="calcul(1);"/>
    <input type="text" name="res" size="3" readonly value=""/>&nbsp;<B>&nbsp;&nbsp;Title 2</B>
    <BR>

    <!-- Livre # 3 -->
    <input type="text" name="pri" size="3" readonly value="59.99"/>
    <input type="text" name="qte" size="3" onblur="calcul(2);"/>
    <input type="text" name="res" size="3" readonly value=""/>&nbsp;<B>&nbsp;&nbsp;Title 3</B>
    <BR>

    <!-- Livre # 4 -->
    <input type="text" name="pri" size="3" readonly value="26.95"/>
    <input type="text" name="qte" size="3" onblur="calcul(3);"/>
    <input type="text" name="res" size="3" readonly value=""/>&nbsp;<B>&nbsp;&nbsp;Title 4</B><BR><BR>

    <B>Gross amount/B>
    <input type="text" name="total" size="3" readonly value=""/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Qty ordered/B>
    <input type="text" name="totalqty" size="3" readonly value=""/>
    <BR><BR>

    <!-- TPS -->
    <b>Applicable taxes/b><BR>
    <!-- CANADA -->
    <input type="radio" name="exp" size="3" readonly value=""/>Shipping in Canada:
    TPS: 7.00% (Rxxx.xxxx)<input type="text" name="tpscan" size="3" readonly value=""/>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <!-- TPS non applicables -->
    <input type="radio" name="exp" size="3" readonly value=""/> Shipping outside Canada:
    <input type="text" name="tpsautre" size="3" readonly value=""/>
    <BR><BR>

    <b>Shipping cost</b><BR>
    <input type="radio" name="expd" size="3" readonly value=""/>Canada:
    <input type="text" name="canexpd" size="3" readonly value=""/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <input type="radio" name="expd" size="3" readonly value=""/> USA:
    <input type="text" name="usexpd" size="3" readonly value=""/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    <input type="radio" name="expd" size="3" readonly value=""/>Other countries:
    <input type="text" name="autrexpd" size="3" readonly value=""/><BR><BR>

    <input type="submit" value="Go!">
    <input type="reset" value="Erase!">
    </FORM>

    </BODY>
    </HTML>

  4. #4
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is where to start but tou will have to do this for all other the controls
    bon courage !
    Code:
    function calcul(ind)
    {
    var Gros=document.getElementsByName('res')
    var Prix=document.getElementsByName('pri')
    var Quant=document.getElementsByName('qte')
     
    Gros[ind].value=Number(Prix[ind].value)*Number(Quant[ind].value);
    total.value=0;
    
    for (var n=0;n<Gros.length;n++)
    {total.value=Number(total.value)+Number(Gros[n].value); }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •