471,887 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

calculation and onchange

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

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";
case 2:
logo_tot.value = "359";
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>
<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">
<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">
<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">

if anyone can help it will much be appreasiated!
May 24 '07 #1
3 2170
16,027 Expert Mod 8TB
In your switch statement, change the integers to strings, i.e. 1 should be '1', etc.
May 25 '07 #2
5,390 Expert Mod 4TB
yep ... alternativly you may typecast the curSel-value to numbers:

Expand|Select|Wrap|Line Numbers
  1. // apply that to that switch-statement
  3. switch (parseInt(curSel)) {
  4.     // your code here
  5. }
May 25 '07 #3
16,027 Expert Mod 8TB
yep ... alternativly you may typecast the curSel-value to numbers:
Yes, that too!
May 26 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by pmarisole | last post: by
14 posts views Thread by ap.sakala | last post: by
5 posts views Thread by The alMIGHTY N | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.