help! onchange and calculation

have an html form with three fields that need to calculate the total and onchange put the amount on a text field, should be simple enough for the gurus, I started it but cannot get it right. Here is the formula:
Logo Solutions: (LIST)
Starter Package - $159
Pro Package - $359
Wholistic Package - $659

Promtional Code: (TEXT)
NU0507

If Starter Discount = -$25
If Pro Discount = -$50
If Wholistic Discount = -$100

Priority Rush: (CHECK)
Priority Rush - +$99

Order Total: (DYNAMIC)
Displays the total

as you can see the package list has the prices, that need to total and if they put in the promo code NU0507
then they get the discount outlined above accordingly, and one more loop is if they check the rush checkbox it adds 99 to total
Simple caclutation, just my javascript is'nt so good, Here is the function I started writing, though with it I could'nt even get the onchage to fire:
Plus also now the total text field has the 659 in it as defualt but does not change as I select the list box.
here is the function as I have it set:
function Change_Selection() {
var logo_list = document.getElementById("pack");
var logo_tot = document.getElementById("logo_total");
var curSel = logo_list.options[logo_list.selectedIndex].value;
switch (curSel) {
case 1:
logo_tot.value = "159";
break;
case 2:
logo_tot.value = "359";
break;
default:
logo_tot.value = "659";
}
}

And here is the form code as I have it now:

<select name="pack" id="pack" onChange="Change_Selection()">
<option value="1" selected>
<option value="1" selected>Starter Package</option>
Starter Package
<option value="2">Pro Package</option>
<option value="3">Wholistic Package</option>
</select>
</label></td>
</tr>
<tr bgcolor="#ffffff">
<td height="2" bgcolor="#FFFFFF"><span class="style10">Promo Code </span></td>
<td height="2" colspan="3"><label>
<input name="code" type="text" id="code">
</label></td>
</tr>
<tr bgcolor="#ffffff">
<td height="2" bgcolor="#FFFFFF"><span class="style10">Proirity rush </span></td>
<td height="2" colspan="3"><label>
<input name="rush" type="checkbox" id="rush" value="99">
</label></td>
</tr>
<tr bgcolor="#ffffff">
<td height="2" bgcolor="#FFFFFF"><span class="style10">Total</span></td>
<td height="2" colspan="3"><label>
<input name="logo_total" type="text" id="logo_total">
</label></td>
</tr>

if anyone can help it will much be appreasiated!
[2915 byte] By [tracy36] at [2007-11-20 8:06:23]
# 1 Re: help! onchange and calculation
First off, let me say that if this is actually going to be sold, you must use server-side scripting or else your security will be horrific. Also, I hope this isn't homework.

Try...
<script type="text/javascript">
function updateprice(chk){
var promo = document.getElementById('code').value;

var totalamount = document.getElementById('pack').value;
if(promo.toUpperCase() == 'NU0507'){
if(document.getElementById('pack').value == 159){totalamount = parseInt(totalamount, 10) - 25;}
if(document.getElementById('pack').value == 359){totalamount = parseInt(totalamount, 10) - 50;}
if(document.getElementById('pack').value == 659){totalamount = parseInt(totalamount, 10) - 100;}
}

if(chk){totalamount = parseInt(totalamount, 10) + 99;}
document.getElementById('logo_total').value = totalamount;
}
</script>

<select name="pack" id="pack" onchange="updateprice(false)">
<option value="159">Starter Package</option>
<option value="359">Pro Package</option>
<option value="659">Wholistic Package</option>
</select><br>
Promo Code<br>
<input name="code" type="text" id="code" onchange="updateprice(false)"><br>
Priority rush<br>
<input name="rush" type="checkbox" id="rush" onchange="updateprice(this.checked)">
Total<br>
<input name="logo_total" type="text" id="logo_total" value="159">
PeejAvery at 2007-11-8 0:42:27 >