JavaScript - Get Total
Dear Coders
var amount1=12,345,678.10 var amount1=87,246,125.00 I want to sum amount1+amount2 as 99,591,803.10 Please help Similar TutorialsGood day! I am new in javascript function. I have Javascript code for auto calculate here is the code: Code: <script type="text/javascript" language="javascript"> function autocalearn(oText) { if (isNaN(oText.value)) //filter input { alert('Numbers only!'); oText.value = ''; } var field, val, oForm = oText.form, TotEarn = a = 0; for (a; a < arguments.length; ++a) //loop through text elements { field = arguments[a]; val = parseFloat(field.value); //get value if (!isNaN(val)) //number? { TotEarn += val; //accumulate } } var tot=Number(TotEarn) + Number(document.getElementById('Amount').value); oForm.TotEarn.value = tot.toFixed(2); //oForm.TotEarn.value = TotEarn.toFixed(2); //out } </script> <!--Total Deduction AutoCompute--> <script type="text/javascript" language="javascript"> function autocalded(oText) { if (isNaN(oText.value)) //filter input { alert('Numbers only!'); oText.value = ''; } var field, val, oForm = oText.form, TotalDed = a = 0; for (a; a < arguments.length; ++a) //loop through text elements { field = arguments[a]; val = parseFloat(field.value); //get value if (!isNaN(val)) //number? { TotalDed += val; //accumulate } } //oForm.TotalDed.value = TotalDed.toFixed(2); //out var totded=Number(TotalDed) + Number(document.getElementById('Deductions').value); oForm.TotalDed.value = totded.toFixed(2); } </script> and now my problem is...I have a textbox for the overall total, and i want it automatic subtract the total earn and total deduction.. I will attach my codes for further understanding. Thank you in advance I currently have a script setup in HTML that will allow me too input a "Customers ID" and their "Gas Usage". Once those are entered, it will do some calculations and display text stating: > "Customers ID: 1 has gas usage of 50 and owes $100 > > Customers ID: 2 has gas usage of 120 and owes $195 > > Customers ID: 3 has gas usage of 85 and owes $142.5 > > Customers ID: 4 has gas usage of 65 and owes $112.5 > > Total amount of customers is: > > Total amount owed all customers:" **What im having trouble** with is making a running total that will calculate the "Total amount of customers" and the "Total amount owed by customers". All I know is that I may need to add another variable in the script. Code: function Summarise() { ID = prompt("Enter a Customer ID number ", -1) while(ID != -1) { var gasUsed = 0 gasUsed = prompt("Enter amount of gas used ", "0") var total = 0 ///Standard Rate is used to assist in the calculation of customers in excess of 60 Gas Used StandardRate = 60 * 1.75 if(gasUsed <= 60) { total= gasUsed * 2 document.write("Customers ID: " + ID) document.write(" has gas usage of " + gasUsed) document.write(" and owes $" + total) document.write("<br/>") } else { total= (gasUsed - 60) * 1.50 + StandardRate document.write("Customers ID: " + ID) document.write(" has gas usage of " + gasUsed) document.write(" and owes $" + total) document.write("<br/>") } ID = prompt("Enter a Customer ID number ", -1) } } <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> Code: <script type='text/javascript'> <!-- function writeSummary() { var desiredquantity = document.orders.value; if (desiredquantity='') { alert('Please enter a value for the desired quantity'); return false; } else if (desiredquantity='value<0') { alert('Please enter a value for the desired quantity that is greater than 0'); return false; } else (desiredquantity='value>0') { alert('Thank you for your order!'); return true; } } //--> </script> </head> <body> <form name="Orders"; action=""; onSubmit="return writeSummary();"> <table width="80%" align="center"> <tbody> <tr> <td><<img SRC = "nwlogo.jpg" img align="right" style="width:200px; height:174px" height="174" width="200"></td> <td><big><b> 3-Season Tent</big></b></td> </tr> </tbody> </table> <p> <table width="80%" border="5" cellspacing="3" cellpadding="5" align="center"> <tbody> <tr> <th width="20%">Selection</th> <th width="20%">Size</th> <th width="20%">Color</th> <th width="20%">Price</th> <th width="20%">In Stock?</th> </tr> <tr> <td align="middle"></td> <td align="middle">Rectangular</td> <td align="middle">Blue</td> <td align="middle">259.99</td> <td align="middle">Yes</td> </tr> </tbody> </table> </p> <p> <table width="80%" cellspacing="3" cellpadding="5" align="center"> <tbody> <tr> <td width="70%"><big>Desired Quantity</big><input type="text" name="userid" size="20"></td> <td align="right" width="15%"><input type="button" name="subbtn" value="Submit"/></td> </tr> </tbody> </table> </p> <p> <table width="80%" align="center" border="" id="Table1"> <tbody> <tr> <td align="right">Subtotal: <input type="text" name="userid" size="20"></td> <td></td> </tr> <tr> <td align="right">Tax: <input type="text" name="userid" size="20"></td> <td></td> </tr> <tr> <td align="right">Order Total: <input type="text" name="userid" size="20"></td> <td></td> </tr> </tbody> </table> </p> </form> </body> </html> Need help with the javascript coding portin of the web page. Need it to use the pop up alerts that have been input above and also to calculate the order upon entering a correct amount showing subtotal, tax, and total. I am having a bit of trouble adding the drop down options to the running total. I managed to get the check boxes and radio buttons to work fine, but can't figure out how to get the drop downs working. Basically when small is selected it adds $10 to the running total, medium $15 and large $20. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pizza</title> <script type="text/javascript"> function CalculateTotal(inputItem) { var frm=inputItem.form; if (!frm.fields) frm.fields=''; if (!frm.fields.match(inputItem.name)) frm.fields+=inputItem.name+',' // add the inputItem name to frm.fields var fieldary=frm.fields.split(','); // convert frm.fields to an array var cal=0; for (var zxc0=0;zxc0<fieldary.length-1;zxc0++){ // loop through the field names var input=document.getElementsByName(fieldary[zxc0]); // an array of fields with the mame for (var zxc0a=0;zxc0a<input.length;zxc0a++){ // loop through the input array to detect checked fields if (input[zxc0a].checked) cal+=input[zxc0a].value*1; // convert the value to a number and add to cal } } frm.calculatedTotal.value=cal; frm.total.value=formatCurrency(cal); } // format a value as currency. function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } // This function initialzes all the form elements to default values function InitForm() { //Reset values on form var frm=document.selectionForm; frm.total.value='$0.00'; // set initial total frm.calculatedTotal.value=0; frm.previouslySelectedRadioButton.value=0; //Set all checkboxes and radio buttons on form to unchecked: for (i=0; i < frm.elements.length; i++) { if (frm.elements[i].type == 'checkbox' || frm.elements[i].type == 'radio') { frm.elements[i].checked =(frm.elements[i].value!='0.00')? false:true; } } } </script> </head> <body onLoad="InitForm();" onreset="InitForm();"> <table width="770" height="171" border="1" cellpadding="3"> <tr> <td colspan="2"><p>PIZZA ORDERS SCREEN Welcome: [username] Time: [current time] </p> <p>Select the requirements of the CLIENT's pizza below</p></td> </tr> <tr> <td width="462"><form method="POST" name="selectionForm"> <fieldset> <legend>NEW PIZZA SELECTION</legend> (pricing estimate) <p>Select the size pizza (base price of all types): <select name="SIZE" > <option name="small" value=10.0 selected>small ($10)</option> <option name="medium" value=15.00 onchange="CalculateTotal(this);">medium ($15)</option> <option name="large" value=20.00 >large ($20)</option> </select> </p> Select pizza type: <table width="292"> <tr> <td><label> <input type="radio" name="type" value="radio" id="RadioGroup1_0" /> Supreme <input type="radio" name="type" value="radio" id="RadioGroup1_1" /> Meat Lovers <input type="radio" name="type" value="radio" id="RadioGroup1_2" /> Aussie</label></td> </tr> </table> <p>Select additional topping (each topping is $2.50): </p> <table width="200" border="0" cellspacing="5" cellpadding="1"> <tr> <td width="70">Ham: </td> <td width="111"> <input type="checkbox" name="ham" value=2.50 onclick="CalculateTotal(this);"></td> </tr> <tr> <td width="70">Cheese: </td> <td width="111"> <input type="checkbox" name="cheese" value=2.50 onclick="CalculateTotal(this);"></td> </tr> <tr> <td width="70">Olives: </td> <td width="111"> <input type="checkbox" name="olives" value=2.50 onclick="CalculateTotal(this);"></td> </tr> <tr> <td width="70">Peppers: </td> <td width="111"> <input type="checkbox" name="peppers" value=2.50 onclick="CalculateTotal(this);"></td> </tr> <tr> <td width="70">Anchovies: </td> <td width="111"> <input type="checkbox" name="anchovies" value=2.50 onclick="CalculateTotal(this);"></td> </tr> <tr> <td width="70">Salami: </td> <td width="111"> <input type="checkbox" name="salami" value=2.50 onclick="CalculateTotal(this);"></td> </tr> </table> <p> </p> <p>Select the type of packaging: </p> <table width="200"> <tr> <td> <input type="radio" name="Sauce" value=1.00 onClick="CalculateTotal(this);"> Plastic $1.00 </td> </tr> <tr> <td> <input type="radio" name="Sauce" value=1.00 onClick="CalculateTotal(this);"> Plastic $1.00 </td> </tr> <tr> <td> <input type="radio" name="Sauce" value=1.00 onClick="CalculateTotal(this);"> Plastic $1.00 </td> </tr> </table> <p> <input type="hidden" name="calculatedTotal" value=0> <input type="hidden" name="previouslySelectedRadioButton" value=0> <font size=+1> Your total is: </font><font face=Arial size=2><font size=+1> <input type="text" name="total" readonly onFocus="this.blur();"> <br /> </p> <p> <input type="button" name="resetBtn" id="resetBtn" value="Reset" /> <input type="button" name="confirmBtn" id="confirmBtn" value="ADD TO ORDER" /> </p> </fieldset> </form></td> <td width="284" align="left" valign="top"> <form id="summaryForm" name="summaryForm" method="post" action=""> <fieldset><legend>CLIENT ORDER SUMMARY</legend> <p> <textarea name="summaryBox" cols="40" rows="20"></textarea> </p> <p>Number of Pizza's: <label for="noPizza"></label> <input name="noPizza" type="text" id="noPizza" size="5" /> </p> <p>Total for Pizza's: <input name="totPizza" type="text" id="totPizza" size="8" /> </p> <p>Email a confirmation: <input type="submit" name="email" id="email" value="KITCHEN CONFIRMATION" /> <br /> </p></fieldset> </form> <p> </p></td> </tr> <tr> <td colspan="2" align="right"><form id="form1" name="form1" method="post" action=""> <input type="button" name="reset all" id="reset all" value="RESET for New client" /> <input type="hidden" name="calculatedTotal" value=0> <input type="hidden" name="previouslySelectedRadioButton" value=0> </font> </p> </form></td> </tr> <tr> </table> </body> </html> Hi, I admit from the start, I'm not very good with JS, I've used it a few times over the years, but mostly readymade scripts that I can just link to a website and use. Anyway, I need something somewhat specific and I don't know where to find such a code or even if I can modify the one I have found to do what I need. What I need is to be able to update totals on the page as things are changed, but I'm not talking about one total. What I have is a list of spare parts with a quantity box next to them, when someone changes the quatity the price for that part needs to update as well as the total price AND a sum that is an allocated amount minus the total (so they can see how much of their allocation they have left). So far, all I've managed to find is a script that will update just the final total (http://www.mcfedries.com/JavaScript/OrderTotals.asp), but as you can see, that's not that helpful. I've sat and stared at the code and while I can say what things do what, I wouldn't know where to start in changing it. Hope someone can help! Thanks Form cap: http://img38.imageshack.us/img38/8118/partlist.png Hi, I am new here and am hoping for some guidance or a solution. Any help is greatly appreciated. I have a total count in a shopping cart stored from PHP as a cookie. I.E. compare[233], compare[324] (where the id is the item ID). I want to update the count of items in the cart in real time, so when the visitor clicks "Add", the count will update without reloading the page. Currently, I can get PHP to count the cookies, but not JS. The problem that I am having is that if the items are 7, and an item is added it will go to 8 correctly, if another item is added it goes to 14, not 9. This is the code that I have so far: Code: <?php $saved_ct = $number_of_items_already_in_cart; // # of cookies found or 'compare' I.E. 7 ?> <script type="text/javascript"> function increase(){ var i=<?php echo "$saved_ct"; ?>; i++; document.getElementById('i').innerHTML= + i; } </script> Cart: (<b id=\"saved_ct\">{$saved_ct}</b>) --- Item: <a href=\"#\" id=\"{$id}\" onclick=\"increase();return false\">Add to basket</a> Hi All, I need help on how to subtract totalgift if my condition of donateamount is lesser than the totalgift trigger. When the field is selected and the DonateAmount is trigger, I need to subtract the entered amount on the field selected to the TotalGift and put the field selected to zero "0" and TotalGift to original amount which is less than the amount entered on the field selected. I have some code that I created but it doesn't work. My initial javascript to calculate all the total is below assuming that DonateAmount is already selected = 25: Code: /* this function works fine with the set of code*/ function CalculateTotal(donate_amount_other) { var tota = document.getElementById('a').value; var totb = document.getElementById('b').value; var totc = document.getElementById('c').value; var totd = document.getElementById('d').value; var tote = document.getElementById('e').value; var totf = document.getElementById('f').value; var totg = document.getElementById('g').value; var toth = document.getElementById('h').value; var toti = document.getElementById('i').value; var totj = document.getElementById('j').value; var totk = document.getElementById('k').value; var totl = document.getElementById('l').value; var totm = document.getElementById('m').value; var totn = document.getElementById('n').value; var toto = document.getElementById('o').value; var totp = document.getElementById('p').value; var totq = document.getElementById('q').value; var totr = document.getElementById('r').value; var TotC = document.getElementById('TotalC').value; TotC = Number(tota) + Number(totb) + Number(totc) + Number(totd) + Number(tote) + Number(totf) + Number(totg) + Number(toth) + Number(toti) + Number(totj) + Number(totk) + Number(totl) + Number(totm) + Number(totn) + Number(toto) + Number(totp) + Number(totq) + Number(totr); document.getElementById('TotalC').value = TotC.toFixed(2); if (isNaN(TotC)) { // if grandTotal is not a number alert ("You must enter numbers 0-9 only in the boxes"); document.getElementById('TotalC').value = "ERROR"; // or perhaps value = "ERROR!" return false; } /* the condition below triggers only when the toti - totr fields are entered less than 48 but still need to subtract the total if TotalGift is greater than DonateAmount given */ if (toti >0 && toti <48 ) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('i').value = "0"; // or perhaps value = "ERROR!" return false; } if (totj >0 && totj <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('j').value = "0"; // or perhaps value = "ERROR!" return false; } if (totk >0 && totk <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('k').value = "0"; // or perhaps value = "ERROR!" return false; } if (totl >0 && totl <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('l').value = "0"; // or perhaps value = "ERROR!" return false; } if (totm >0 && totm <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('m').value = "0"; // or perhaps value = "ERROR!" return false; } if (totn >0 && totn <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('n').value = "0"; // or perhaps value = "ERROR!" return false; } if (toto >0 && toto <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('o').value = "0"; // or perhaps value = "ERROR!" return false; } if (totp >0 && totp <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('p').value = "0"; // or perhaps value = "ERROR!" return false; } if (totq >0 && totq <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('q').value = "0"; // or perhaps value = "ERROR!" return false; } if (totr >0 && totr <48) { alert ("All donations in this section must be $48 minimum (processing fee may apply) - please revise your entry to avoid any processing errors"); document.getElementById('r').value = "0"; // or perhaps value = "ERROR!" return false; } /* The code below works if I only check the TotalGift is greater than DonateAmount but will cannot do subtraction to the TotalGift and the entered amount. */ if ((DonateText < TotC)) { alert('Your total designated amount of $' + TotC + ' is more than your donation amount of $' + DonateText + '. Please revise your entry to avoid any processing errors.'); //add if here for all fields focus document.getElementById('TotalC').value = TotC; // or perhaps value = "ERROR!" document.getElementById('TotalC').focus(); return false; } } Below is what I am trying to do but it doesn't work. If the first input field is selected and user enter amount greater than the TotalGift, alert will pop-up then and the amount entered by the user automatically added to the TotalGift. So what I wanted to do is to subtract the amount entered to the TotalGift so it will go back to the original amount before the addition occurs. I know it is possible but I just can't get the right code. Can you please help? I need to make this done as soon as possible, please!!!!! Code: if ((DonateText < TotC) && (document.getElementById('a').value)) { alert('Your total designated amount of $' + TotC + ' is more than your donation amount of $' + DonateText + '. Please revise your entry to avoid any processing errors.'); //add if here for all fields focus if (TotC = "0.00") { document.getElementById('a').value=0; document.getElementById('TotalC').value = TotC; // or perhaps value = "ERROR!" } else { TotC = TotC - document.getElementById('a').value; document.getElementById('tota').value = "0"; document.getElementById('TotalC').value = TotC; // or perhaps value = "ERROR!" document.getElementById('TotalC').focus(); return false; } } if ((DonateText < TotC) && (document.getElementById('b').value)) { alert('Your total designated amount of $' + TotC + ' is more than your donation amount of $' + DonateText + '. Please revise your entry to avoid any processing errors.'); if (TotC = "0.00") { document.getElementById('b').value=0; document.getElementById('TotalC').value = TotC; // or perhaps value = "ERROR!" } else { TotC = TotC - document.getElementById('b').value; document.getElementById('totb').value = "0"; document.getElementById('TotalC').value = TotC; // or perhaps value = "ERROR!" document.getElementById('TotalC').focus(); return false; } } /* so on My html code below which I have 18 input fields but all of them only optional wherever the user wants to input number. I will only include some here. Code below works, please ignore any missing code. I just need the calculation code to work. PHP Code: <label>Donation Amount: $</label> <input name="TotalDonate" id="TotalDonate" type="text" maxlength="10" readonly="true" onClick="CalculateTotal(this.value,99);" /> <label for="agencysupport" style="font-weight:bold">C. Agency/Program Support ($48 MINIMUM PER CHOICE)</label> <BR /> <p style="color:#000000">My gift is designated to one or more specific agencies or programs. Processing fee may apply. </p> <p style="color:#FF0000">(Note: Some Agency Names may be indented on the next line due to space allowed. Choosing either one of the Agency Names will give you the same code.)</p> <table> <tr> <td> <select id="designation_list1" name="designation_list1" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list1']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="i" name="i" class="text" type="text" value="<?php safeEcho($form['i'])?>" style="width:90px;" onChange="CalculateTotal()"/> <?php helper_error('i');?> </td> </tr> <tr> <td> <select id="designation_list2" name="designation_list2" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list2']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="j" name="j" class="text" type="text" value="<?php safeEcho($form['j'])?>" style="width:90px;" onChange="CalculateTotal()"/> <?php helper_error('j');?> </td> </tr> <tr> <td> <select id="designation_list3" name="designation_list3" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list3']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="k" name="k" class="text" type="text" value="<?php safeEcho($form['k'])?>" style="width:90px;" onChange="CalculateTotal()"/> <?php helper_error('k');?> </td> </tr> <tr> <td> <select id="designation_list4" name="designation_list4" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list4']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="l" name="l" class="text" type="text" value="<?php safeEcho ($form['l'])?>" style="width:90px;" onChange="CalculateTotal()"/> <?php helper_error('l');?> </td> </tr> <tr> <td> <select id="designation_list5" name="designation_list5" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list5']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="m" name="m" class="text" type="text" value="<?php safeEcho($form['m'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('m');?> </td> </tr> <tr> <td> <select id="designation_list6" name="designation_list6" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list6']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="n" name="n" class="text" type="text" value="<?php safeEcho($form['n'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('n');?> </td> </tr> <tr> <td> <select id="designation_list7" name="designation_list7" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list7']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="o" name="o" class="text" type="text" value="<?php safeEcho($form['o'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('o');?> </td> </tr> <tr> <td> <select id="designation_list8" name="designation_list8" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list8']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="p" name="p" class="text" type="text" value="<?php safeEcho($form['p'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('p');?> </td> </tr> <tr> <td> <select id="designation_list9" name="designation_list9" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list9']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="q" name="q" class="text" type="text" value="<?php safeEcho($form['q'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('q');?> </td> </tr> <tr> <td> <select id="designation_list10" name="designation_list10" size="1" style="overflow-x:scroll; width:380px; "> <option>Click to select...</option> <?php foreach ($designation_list as $descode => $prompt) : ?> <option <?php echo helper_selected($descode == $form['designation_list10']); ?> value="<?php echo $prompt; ?>" ><?php safeEcho($descode); ?> </option> <?php endforeach; ?> </select> </td> <td> $<input id="r" name="r" class="text" type="text" value="<?php safeEcho($form['r'])?>" style="width:90px;" onChange="CalculateTotal();"/> <?php helper_error('r');?> </td> </tr> <tr> <td style="text-align:right; font-size:14px"><b>TOTAL GIFT(S) DESIGNATED (A-C)</b><BR /> (Must not exceed donation amount)</td> <td>$<input name="TotalC" id="TotalC" type="text" maxlength="10" value="<?php echo $TotalC; ?>" readonly="true" onChange="CalculateTotal(this.value,99);" style="width:90px" /></td> </tr> </table> Please, I really need to make this work today. Hope you can help me please!!!! Thanks in advance. I'm new to javascript here my script that only in one row the Gross, Cost and Net but is another row with a different amounts it show the script is not working any more can you please help to allow to onClick buttom in my form update the amount will change wherether in row #1 or row # or any row in form. thanks <script language="JavaScript"> function UpdateQty() { var TotalGross = parseFloat(document.frmUpdateQty.TotalGross.value.substring(1,10000)); var TotalCost = parseFloat(document.frmUpdateQty.TotalCost.value.substring(1,10000)); var TotalNet = parseFloat(document.frmUpdateQty.TotalNet.value.substring(1,10000)); var QTotal = parseInt(document.frmUpdateQty.QTotal.value); document.frmUpdateQty.TotalGross.value = "$"+(QTotal * TotalGross).toFixed(2); document.frmUpdateQty.TotalCost.value = "$"+(TotalCost * QTotal).toFixed(2); document.frmUpdateQty.TotalNet.value = "$"+(QTotal * TotalGross - TotalCost * QTotal).toFixed(2); document.frmUpdateQty.Button.disabled = true; } </script> I looked around for a solution but could not find one. I am trying to find combinations of numbers that can add up to a total. The numbers available and the total are different each time. For example, I have an array that contains the following numbers: [16,12,8,6,4,2] I want to find the combinations that add up to 140, like this: 8x16,1x12 8x16,1x8,1x4 11x12,1x8 Notice I do not do: 8x16,2x6 8x16,3x4 This is because as a rule, only the first number can be used in multiple of more than one. All other number pairs can only be a 1x. Output string could be formatted like this in a single string containing all combinations: 8x16,1x12|8x16,1x8,1x4|11x12,1x8 I'm creating a web form that allows users to select from a list, choose a quantity and have the total for that quantity calculated, but when I run the html, I get Nan in the total price box. The problem starts with the calc price function. I've tried eval(), parseFloat to change the text to a number, but I think I'm putting the code in the wrong place. I would greatly appreciate any input I can get -- thanks in advance! The first part is the javascript code (I have linked in a separate file) with the html below it. Code: window.onload = startForm; function todayTxt() { var Today = new Date(); return Today.getMonth() + 1 + "-" + Today.getDate() + "-" + Today.getFullYear(); } function startForm(){ document.forms[0].date.value = todayTxt(); document.forms[0].prod.focus(); document.forms[0].prod.onchange = calcPrice; document.forms[0].qty.onchange = calcPrice; for (var i=0; i<document.forms[0].shipType.length; i++) { document.forms[0].shipType[i].onclick = calcShipping; } } function calcPrice() { product=document.forms[0].prod; pIndex=product.selectedIndex; productPrice=product.options[pIndex].value; //returns the price of the selected product quantity=document.forms[0].qty; qIndex=quantity.selectedIndex; quantityOrdered=quantity.options[qIndex].value; //returns the index of the selected quantity document.forms[0].price.value = eval(product.Price*quantityOrdered); //cost is equal to product price multiplied by quantity ordered } function calcShipping() { document.forms[0].ship.value = this.value;} function calcTotal() { priceVal=parseFloat(document.forms[0].price.value); shipVal=parseFloat(document.forms[0].ship.value); document.forms[0].sub.value = priceVal + shipVal; taxVal = 0.05*(priceVal + shipVal); document.forms[0].tax.value = taxVal; document.forms[0].tot.value = priceVal + shipVal + taxVal; } <html> <body> <form id="form1" method="post" action="form2.htm"> <div id="links"> <a href="#" class="newgroup">Home Page</a> <a href="#">Product Catalog</a> <a href="#">Order Form</a> <a href="#">Maps Online</a> <a href="#">Contact Us</a> <a href="#" class="newgroup">Countries</a> <a href="#">States</a> <a href="#">National Parks</a> <a href="#">Hiking Trails</a> <a href="#">Cities</a> <a href="#">Astronomical</a> <a href="#">Natural</a> <a href="#" class="newgroup">GoMap 1.0</a> <a href="#">Drive Planner 2.0</a> <a href="#">Hiker 1.0</a> <a href="#">G-Receiver I</a> <a href="#">G-Receiver II</a> <a href="#">G-Receiver III</a> <a href="#" class="newgroup">Downloads</a> <a href="#">Tech Support</a> <a href="#">FAQs</a> </div> <div id="main"> <p id="logo"><img src="gpsware.jpg" alt="GPS-ware" /></p> <h1>Order Form</h1> <p id="datep"> <input class="text" id="date" name="date" size="11" value="mm-dd-yyyy" readonly="readonly" /> </p> <fieldset> <legend>Select a Product</legend> <table> <tr> <td class="labelcell">Product</td> <td class="inputcell"> <select name="prod" id="prod"> <option value="0">Products from GPS-ware</option> <option value="19.95">GoMap 1.0 ($19.95)</option> <option value="29.95">Drive Planner 2.0 ($29.95)</option> <option value="29.95">Hiker 1.0 ($29.95)</option> <option value="149.50">G-Receiver I ($149.50)</option> <option value="199.50">G-Receiver II ($199.50)</option> <option value="249.50">G-Receiver III ($249.50)</option> </select> <select name="qty" id="qty"> <option value="0">Quantity</option> <option value="1">1</option><option value="2">2</option><option value="3">3</option> <option value="4">4</option><option value="5">5</option><option value="6">6</option> <option value="7">7</option><option value="8">8</option><option value="9">9</option> <option value="10">10</option> </select> </td> <td class="outcell"> <input class="num" name="price" id="price" size="7" value="0.00" readonly="readonly" /> </td> </tr> <tr> <td class="labelcell">Shipping</td> <td> <p><input type="radio" name="shipType" id="ship1" value="4.95" /> <label for="ship1">Standard (4-6 business days): $4.95</label> </p> <p><input type="radio" name="shipType" id="ship2" value="8.95" /> <label for="ship2">Express (2 days): $8.95</label> </p> <p><input type="radio" name="shipType" id="ship3" value="12.95" /> <label for="ship3">Next Day (1 day): $12.95</label> </p> </td> <td class="outcell"> <input class="num" name="ship" id="ship" size="7" value="0.00" readonly="readonly" /> </td> </tr> <tr> <td colspan="2" class="labelcell2">Subtotal</td> <td class="outcell"> <input class="num" name="sub" size="7" value="0.00" readonly="readonly" /> </td> </tr> <tr> <td colspan="2" class="labelcell2">Tax (5%)</td> <td class="outcell"> <input class="num" name="tax" id="tax" size="7" value="0.00" readonly="readonly" /> </td> </tr> <tr> <td colspan="2" class="labelcell2">TOTAL</td> <td class="outcell"> <input class="num" name="tot" id="tot" size="7" value="0.00" readonly="readonly" /> </td> </tr> </table> </fieldset> <p id="formbuttons"> <input type="reset" name="cancelb" id="cancelb" value="Cancel" /> <input type="submit" name="nextb" id="nextb" value="Next" /> </p> </div> </form> </body> </html> Hello guys, I'm having some problems with jquery.. What I'm trying to do is, a jquery script to show in real time the total price. I got this: Code: <li>Users</li> <li> <select name="users" id="users"> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> <option value='9'>9</option> <option value='10'>10</option> </select> </li> <li>Months</li> <li> <select name="months" id="months"> <option value='1'>1 Month</option> <option value='2'>2 Months</option> <option value='3'>3 Months</option> <option value='4'>4 Months</option> <option value='5'>5 Months</option> <option value='6'>6 Months</option> <option value='7'>7 Months</option> <option value='8'>8 Months </option> <option value='9'>9 Months</option> <option value='10'>10 Months</option> <option value="11">11 Months</option> <option value="12">12 Months</option> </select> </li> <div class="grand_total"> <h4 class="colr">Price</h4> <ul> <li class="price">$0.50</li> </ul> </div> 1 Month and 1 User price should be 0.50 USD +1 Month = + 0.50 USD + 1 User = + 0.50 USD Example: 5 Users + 2 Months = 3.50 USD I wanna make the jquery to show the total price at li class="price" Sorry, I'm newbie at jquery. Anyone could help me please? Thank you. Quote: The parameter A should display the sum of the remaining six fields. I did try adding that using the JAVA script that is mentioned in second code. The total should be display immediately after value is set for any of the text boxes. The text box gets the value using drop down menu. This procedure only works if I use the keyboard tab. If I use the mouse to select YES and No, then it will not display the total Code: <html> <head> <script type="text/javascript" src="javascript/addfunctions.js"></script> <script type="text/javascript"> function enable1() { document.audit_billing_IE.Para_A_A1_comment.disabled = false; document.audit_billing_IE.Para_A_A1_score.value = 00; } function enable2() { document.audit_billing_IE.Para_A_A2_comment.disabled = false; document.audit_billing_IE.Para_A_A2_score.value = 00; } function enable3() { document.audit_billing_IE.Para_A_A3_comment.disabled = false; document.audit_billing_IE.Para_A_A3_score.value = 00; } function enable4() { document.audit_billing_IE.Para_A_A4_comment.disabled = false; document.audit_billing_IE.Para_A_A4_score.value = 00; } function enable5() { document.audit_billing_IE.Para_A_A5_comment.disabled = false; document.audit_billing_IE.Para_A_A5_score.value = 00; } function enable6() { document.audit_billing_IE.Para_A_A6_comment.disabled = false; document.audit_billing_IE.Para_A_A6_score.value = 00; } function disable1() { document.audit_billing_IE.Para_A_A1_comment.disabled = true; document.audit_billing_IE.Para_A_A1_score.value = 10; } function disable2() { document.audit_billing_IE.Para_A_A2_comment.disabled = true; document.audit_billing_IE.Para_A_A2_score.value = 10; } function disable3() { document.audit_billing_IE.Para_A_A3_comment.disabled = true; document.audit_billing_IE.Para_A_A3_score.value = 10; } function disable4() { document.audit_billing_IE.Para_A_A4_comment.disabled = true; document.audit_billing_IE.Para_A_A4_score.value = 10; } function disable5() { document.audit_billing_IE.Para_A_A5_comment.disabled = true; document.audit_billing_IE.Para_A_A5_score.value = 10; } function disable6() { document.audit_billing_IE.Para_A_A6_comment.disabled = true; document.audit_billing_IE.Para_A_A6_score.value = 10; } function na1() { document.audit_billing_IE.Para_A_A1_comment.disabled = true; document.audit_billing_IE.Para_A_A1_score.value = 00; } function na2() { document.audit_billing_IE.Para_A_A2_comment.disabled = true; document.audit_billing_IE.Para_A_A2_score.value = 00; } function na3() { document.audit_billing_IE.Para_A_A3_comment.disabled = true; document.audit_billing_IE.Para_A_A3_score.value = 00; } function na4() { document.audit_billing_IE.Para_A_A4_comment.disabled = true; document.audit_billing_IE.Para_A_A4_score.value = 00; } function na5() { document.audit_billing_IE.Para_A_A5_comment.disabled = true; document.audit_billing_IE.Para_A_A5_score.value = 00; } function na6() { document.audit_billing_IE.Para_A_A6_comment.disabled = true; document.audit_billing_IE.Para_A_A6_score.value = 00; } function changed1(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable1(); if (sel.value == "No")enable1(); if (sel.value == "Na")na1(); } function changed2(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable2(); if (sel.value == "No")enable2(); if (sel.value == "Na")na2(); } function changed3(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable3(); if (sel.value == "No")enable3(); if (sel.value == "Na")na3(); } function changed4(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable4(); if (sel.value == "No")enable4(); if (sel.value == "Na")na4(); } function changed5(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable5(); if (sel.value == "No")enable5(); if (sel.value == "Na")na5(); } function changed6(el) { var sel = el.options[el.selectedIndex]; if (sel.value == "Yes")disable6(); if (sel.value == "No")enable6(); if (sel.value == "Na")na6(); } </script> </head> <body> <form name="audit_billing_IE" method="POST" action="billing.php"> <table> <tr> <td> Parameter A </td> <td colspan='3'> <input type="text" name="product_name4" id="product_name4" /> </td> </tr> <tr> <td> Procedure </td> <td> <select name="Para_A_A1" id = "Para_A_A1" align="center" onchange="changed1(this)"> <option value="s1"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td> <input type="text" name="Para_A_A1_comment" value="" disabled/> </td> <td align="center"> <input type="text" name="Para_A_A1_score" value="" onFocus="startCalc();" onBlur="stopCalc();"/> </td> </tr> <tr> <td> Days Calculation </td> <td> <select name="Para_A_A2" id = "Para_A_A2" align="center" onchange="changed2(this)"> <option value="s2"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td > <input type="text" name="Para_A_A2_comment" value="" disabled/> </td> <td> <input type="text" name="Para_A_A2_score" id="Para_A_A2_score" value="" onFocus="startCalc();" onBlur="stopCalc();"/> </td> </tr> <tr> <td> request form </td> <td> <select name="Para_A_A3" align="center" onchange="changed3(this)"> <option value="s3"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td > <input type="text" name="Para_A_A3_comment" value="" disabled/> </td> <td> <input type="text" name="Para_A_A3_score" id="Para_A_A3_score" value="" onFocus="startCalc();" onBlur="stopCalc();" /> </td> </tr> <tr> <td> Case </td> <td> <select name="Para_A_A4" align="center" onchange="changed4(this)"> <option value="s4"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td > <input type="text" name="Para_A_A4_comment" value="" disabled/> </td> <td> <input type="text" name="Para_A_A4_score" id="Para_A_A4_score" value="" onFocus="startCalc();" onBlur="stopCalc();"/> </td> </tr> <tr> <td> interaction </td> <td> <select name="Para_A_A5" align="center" onchange="changed5(this)"> <option value="s5"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td > <input type="text" name="Para_A_A5_comment" value="" disabled/> </td> <td> <input type="text" name="Para_A_A5_score" id="Para_A_A5_score" value="" onFocus="startCalc();" onBlur="stopCalc();"/> </td> </tr> <tr> <td> MIS</td> <td> <select name="Para_A_A6" align="center" onchange="changed6(this)"> <option value="s6"> Select</option> <option value="Yes"> Yes </option> <option value="No"> No </option> <option value="Na"> Na </option> </select> </td> <td > <input type="text" name="Para_A_A6_comment" value="" disabled/> </td> <td> <input type="text" name="Para_A_A6_score" id="Para_A_A6_score" value="" onFocus="startCalc();" onBlur="stopCalc();"/> </td> </tr> </table> </form> </body> </html> Code: function startCalc(){ interval = setInterval("calc()",1); } function calc(){ one = document.audit_billing_IE.Para_A_A1_score.value; two = document.audit_billing_IE.Para_A_A2_score.value; three = document.audit_billing_IE.Para_A_A3_score.value; four = document.audit_billing_IE.Para_A_A4_score.value; five = document.audit_billing_IE.Para_A_A5_score.value; six = document.audit_billing_IE.Para_A_A6_score.value; document.audit_billing_IE.product_name4.value = [(one * 1) + (two * 1) + (three * 1) + (four * 1) + (five * 1) + (six * 1)]; } function stopCalc(){ clearInterval(interval); } Hi, I would like to display total online viewers on my website, how can i do this? thanks Hi, I need my javascript to calculate a total with 2x decimal figures, not rounded up. Can you help? Here is my code: Code: <script type="text/javascript"> function calculateText() { var op1=document.getElementById('Age02'); var op2=document.getElementById('Girl35'); var op3=document.getElementById('Boy35'); var op4=document.getElementById('Girl610'); var op5=document.getElementById('Boy610'); var op6=document.getElementById('Age11'); var op7=document.getElementById('Guest'); var op8=document.getElementById('VIP'); var op9=document.getElementById('School'); var op10=document.getElementById('3DFilm'); var op11=document.getElementById('BFast'); var op12=document.getElementById('PNGift'); var op13=document.getElementById('PStand'); var op14=document.getElementById('PLrg'); var op15=document.getElementById('PReP'); var op16=document.getElementById('KyMg'); var op17=document.getElementById('SnwGlb'); var op18=document.getElementById('PBbl'); var op19=document.getElementById('USB'); var op20=document.getElementById('SantaL'); var op21=document.getElementById('SantaK'); var op22=document.getElementById('FreeP'); var op23=document.getElementById('PUpgrd'); var op24=document.getElementById('StaffP'); var op25=document.getElementById('CompEntry'); var op26=document.getElementById('241'); var op27=document.getElementById('50Percent'); var op28=document.getElementById('Voucher'); var result=document.getElementById('Total'); if(op1.value=="" || op1.value!=parseFloat(op1.value)) op1.value=0; if(op2.value=="" || op2.value!=parseFloat(op2.value)) op2.value=0; if(op3.value=="" || op3.value!=parseFloat(op3.value)) op3.value=0; if(op4.value=="" || op4.value!=parseFloat(op4.value)) op4.value=0; if(op5.value=="" || op5.value!=parseFloat(op5.value)) op5.value=0; if(op6.value=="" || op6.value!=parseFloat(op6.value)) op6.value=0; if(op7.value=="" || op7.value!=parseFloat(op7.value)) op7.value=0; if(op8.value=="" || op8.value!=parseFloat(op8.value)) op8.value=0; if(op9.value=="" || op9.value!=parseFloat(op9.value)) op9.value=0; if(op10.value=="" || op10.value!=parseFloat(op10.value)) op10.value=0; if(op11.value=="" || op11.value!=parseFloat(op11.value)) op11.value=0; if(op12.value=="" || op12.value!=parseFloat(op12.value)) op12.value=0; if(op13.value=="" || op13.value!=parseFloat(op13.value)) op13.value=0; if(op14.value=="" || op14.value!=parseFloat(op14.value)) op14.value=0; if(op15.value=="" || op15.value!=parseFloat(op15.value)) op15.value=0; if(op16.value=="" || op16.value!=parseFloat(op16.value)) op16.value=0; if(op17.value=="" || op17.value!=parseFloat(op17.value)) op17.value=0; if(op18.value=="" || op18.value!=parseFloat(op18.value)) op18.value=0; if(op19.value=="" || op19.value!=parseFloat(op19.value)) op19.value=0; if(op20.value=="" || op20.value!=parseFloat(op20.value)) op20.value=0; if(op21.value=="" || op21.value!=parseFloat(op21.value)) op21.value=0; if(op22.value=="" || op22.value!=parseFloat(op22.value)) op22.value=0; if(op23.value=="" || op23.value!=parseFloat(op23.value)) op23.value=0; if(op24.value=="" || op24.value!=parseFloat(op24.value)) op24.value=0; if(op25.value=="" || op25.value!=parseFloat(op25.value)) op25.value=0; if(op26.value=="" || op26.value!=parseFloat(op26.value)) op26.value=0; if(op27.value=="" || op27.value!=parseFloat(op27.value)) op27.value=0; if(op28.value=="" || op28.value!=parseFloat(op28.value)) op28.value=0; result.value=0; result.value=parseInt(result.value); result.value=parseInt(result.value)+parseInt(op1.value*5)+parseInt(op2.value*5)+parseInt(op3.value*5)+parseInt(op4.value*5)+parseInt(op5.value*5)+parseInt(op6.value*5)+parseInt(op7.value*0)+parseInt(op8.value*8.50)+parseInt(op9.value*3.75)+parseInt(op10.value*0)+parseInt(op11.value*10)+parseInt(op12.value*5)+parseInt(op13.value*3)+parseInt(op14.value*4)+parseInt(op15.value*2)+parseInt(op16.value*4)+parseInt(op17.value*5)+parseInt(op18.value*3)+parseInt(op19.value*5)+parseInt(op20.value*4)+parseInt(op21.value*3)+parseInt(op22.value*0)+parseInt(op23.value*1)+parseInt(op24.value*0)+parseInt(op25.value*0)+parseInt(op26.value*4)+parseInt(op27.value*2)-parseInt(op28.value); } </script> I have a text field. I want the text field to change / be calculated on the action made on the dropdown menu... So if I select Debit card.. it should leave the amount as is.. If I selected Credit Card it should add a percentage to the Amount. Please dont just provide a solutoin.. but please explain as i would love to understand why Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function doMath() { if (CardType = "cc") { var one = eval(document.myForm.Amount.value) var prod = one * 1.03 document.myForm.Amount.value=custRound(prod,2);} } else document.myForm.Amount.value; function custRound(x,places) { return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places) } </script> </head> <body> <form id="myForm" name="myForm" method="post" action=""> <input name="Amount" type="text" id="Amount" v alue="100" /> <select id="CardType" name="CardType" onchange="doMath();" > <option value="" selected="selected">Please Select</option> <option value="dc">Debit Card</option> <option value="cc">Credit Card</option> </select> </form> </body> </html> Hi all, I am trying to have a form calculate total using this script, works OK until the total reaches 99 from there on it only returns 2 figures. Also it won't work if I complete the dollar value (i.e add .00) Anyone tell me where I am going wrong? Code: <script type="text/javascript"> function startCalc(){ interval = setInterval("calc()",1); } function calc(){ q1 = document.apply.appfee.value = 11; q2 = document.apply.memfee.value = 20; q3 = document.apply.levy.value; q4 = document.apply.donation.value; document.apply.total.value = (q1*1) + (q2*1) + (q3*1) + (q4*1) } function stopCalc(){ clearInterval(interval); } </script> This is the form: Code: <form name="apply" action="" method="post" onsubmit="return validate(apply)"> <table style="width:680px;"> <tr> <td style="text-align:right; white-space:nowrap; width:300px;">Application Fee:</td> <td style="text-align:left; white-space:nowrap; width:441px">$<input type="text" readonly value="" name="appfee" style="width:17px; border:0; font:11px verdana; color:#006;margin-bottom:5px;"></td> </tr> <tr> <td style="text-align:right; white-space:nowrap; width:300px;">Annual Memebership Fee:</td> <td style="text-align:left; white-space:nowrap;">$<input type="text" readonly value="" name="memfee" style="width:17px; border:0; font:11px verdana; color:#006;margin-bottom:5px;"></td> </tr> <tr> <td style="text-align:right; white-space:nowrap; width:300px;">* Optional Annual Levy:</td> <td style="text-align:left;"> $<select name="levy" onFocus="startCalc();" onBlur="stopCalc();"> <option selected>0</option> <option value="22">22</option> <option value="44">44</option> <option value="66">66</option> <option value="88">88</option> <option value="110.00">110</option> </select> </td> </tr> <tr> <td style="text-align:right; white-space:nowrap; width:300px;">* Optional Donation:</td> <td>$<input type="text" name="donation" value="" onFocus="startCalc();" onBlur="stopCalc();" style="font:11px verdana; color:#006;margin-bottom:5px; width:80px;"></td> </tr> <tr> <td style="text-align:right; white-space:nowrap; width:300px;"><b>TOTAL:</b></td> <td white-space:nowrap;><b>$<input type="text" name="total" style="width:17px; border:0; font:bold 11px verdana; color:#006;margin-bottom:6px;"></b></td> </tr> </table> </form> I have my cumulative totals box at the very end of my order form and I'm required to have another underneath that one that will give a particular discount depending on how great the total of the order is. Would someone please be able to give me the javascript codes that will allow me to do this and also tell me where I'm to put them. Hello all. I'm working with a simple shopping page. I basically need to add up all of the values that are found in my query string, and display them as a total on my page. I know how to retrieve each value individually, however I'm a little confused on how to add up the values that are only found in the query string. Please keep in mind, I'm very new to javascripting, and probably won't understand in-depth coding. I have a lot more code to go with this, but I don't think it's required for my question.. Any help would be appreciated! Code: <javascript> var parameters = new Array( ); // <![CDATA[ var qs = document.location.search.substring( 1, document.location.search.length ); var params = qs.split( "&" ); for (var x=0 ; x < params.length ; x++) { var pair = params[ x ].split( "="); parameters.push( new Parameter( pair[ 0 ], pair[ 1 ] ) ); } function get_parameter_value_for_name( name ) { for( var x = 0 ; x < parameters.length ; x++) { if( parameters[ x ].name == name) { return parameters[ x ].name; } } return " "; } function get_parameter_value_for_value( name ) { for( var x = 0 ; x < parameters.length ; x++) { if( parameters[ x ].name == name) { return parameters[ x ].value; } } return " " ; } //]]> </script> Folks, I am trying to calculate the total of fields on a web form. I have multiple rows of 10 fields with a total for each. Each row comes from a different record in a database. I am only showing 2 fields of the 10 for simplicity. The name and id of each field looks like "Q300_1" onchange="update(Q300)" "Q300_2" onchange="update(Q300)" "Q300_t" "Q301_1" onchange="update(Q301)" "Q301_2" onchange="update(Q301)" "Q301_t" My current attempt at the script looks like: [CODE] <script type="text/javascript"> function update(item) { var itemt=item + "_t"; var item1=item + "_1"; var item2=item + "_2"; document.myform[itemt].value = (document.myform[item1].value -0) + (document.myform[item2].value -0); } </script> [CODE] It does not work and I get Error: Q301 is not defined in the Firefox error console. |