...

View Full Version : OnBlur - Sum of #'s



ccwebstuff
12-29-2003, 05:59 AM
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 ?

A1ien51
12-29-2003, 03:29 PM
Your switch statment is wrong

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

Eric

A1ien51
12-29-2003, 03:31 PM
plus you are using FORM and OrderForm....

ccwebstuff
01-02-2004, 02:59 AM
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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum