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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Las Vegas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OnBlur - Sum of #'s

    I'm trying to get the price according to hard qty breaks... nothing is changing using the onblur event...

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

    nQty = eval( document.OrderForm.westernqty.value + document.OrderForm.englishqty.value )

    switch {
    case nQty = 1 :
    document.OrderForm.shipping.value = 11.00
    document.OrderForm.cost.value = 89.00
    break;
    case nQty = 2 :
    document.OrderForm.shipping.value = " * FREE * "
    document.OrderForm.cost.value = eval( 89.00 * 2 )
    break;
    case nQty > 9 :
    document.Form.shipping.value = " * FREE * "
    document.OrderForm.cost.value = eval( 70.00 * nQty )
    break;
    default:
    document.OrderForm.shipping.value = " * FREE * "
    document.Form.cost.value = eval( 75.00 * nQty )
    break;
    }
    }

    Here is basic portion of form

    <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>

    I'm so tired ... been staring/tweaking for hours ...
    What am I missing ?

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Your switch statment is wrong

    http://cyberlearn.fau.edu/cafolla/progjava/Switch.htm

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    plus you are using FORM and OrderForm....
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    New to the CF scene
    Join Date
    Dec 2003
    Location
    Las Vegas
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok -- I've changed the code - see below -- and 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>


  •  

    Posting Permissions

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