Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Las Vegas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiplication Error - OnBlur

    it's giving me a value of $150 for 3 of the western -- why is the math wrong ?

    <script language="javascript">
    <!--
    function add( qty ){
    //-->if more than 1 (western+english) - shipping is 0
    //-->1=89, 2=89, > 2 & < 10 = 75, > 9 = 70

    var nQty = eval( document.EzUpOrderForm.westernqty.value + document.EzUpOrderForm.englishqty.value )

    switch (nQty) {
    case nQty = 1 :
    document.EzUpOrderForm.shipping.value = 11.00
    document.EzUpOrderForm.cost.value = 89.00
    break;

    case nQty = 2 :
    document.EzUpOrderForm.shipping.value = " * FREE * "
    document.EzUpOrderForm.cost.value = eval( 89.00 * 2 )
    break;
    case nQty > 9 :
    document.EzUpOrderForm.shipping.value = " * FREE * "
    document.EzUpOrderForm.cost.value = eval( 70.00 * nQty )
    break;
    default:
    document.EzUpOrderForm.shipping.value = " * FREE * "
    document.EzUpOrderForm.cost.value = eval( 75.00 * nQty )
    break;
    }
    }

    // -->
    </script>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="100%" colspan="4"><font color="#C4816A" face="Arial, Helvetica, sans-serif" size="4"><b>Choose the Quantity of each style that you would like</b></font></td>
    </tr>
    <tr>
    <td width="20%"><font face="Arial" color=#6D69C2 size="4"><b>Western Style</b></font></td>
    <td width="31%"><font face="Arial" color=#C4816A size="4"><b>
    <input type="text" name="westernqty" size="15" value="0" onblur="add(this);" >
    </b></font></td>
    <td width="29%"><font face="Arial" color=#6D69C2 size="4"><b>English Style</b></font></td>
    <td width="20%"><font face="Arial" color=#C4816A size="4"><b>
    <input type="text" name="englishqty" size="15" value="0" onblur="add(this);">
    </b></font></td>
    </tr>
    </table>

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You could try changing

    var nQty = eval( document.EzUpOrderForm.westernqty.value + document.EzUpOrderForm.englishqty.value )

    to

    var nQty = eval( document.EzUpOrderForm.westernqty.value*1 + document.EzUpOrderForm.englishqty.value*1 )


    Would have to see the rest of the script otherwise

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    eval() is unnecessary. If you search eval in this forum, you will find that eval==evil.

    var nQty = parseFloat( document.EzUpOrderForm.westernqty.value) + parseFloat(document.EzUpOrderForm.englishqty.value);

    to make it more efficient and to save typing, put your form reference in a variable

    var f = document.EzUpOrderForm;

    then in your codes:

    var nQty = parseFloat(f.westernqty.value) + parseFloat(f.englishqty.value);


    or instead, pass the form reference to the add() function.

    function add(f){
    var nQty = parseFloat(f.westernqty.value) + parseFloat(f.englishqty.value);
    ...
    }
    ...
    <input type="text" name="westernqty" size="15" value="0" onblur="add(this.form);" >
    <input type="text" name="englishqty" size="15" value="0" onblur="add(this.form);">


  •  

    Posting Permissions

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