JavaScript - Help With Resetting Values When Hitting Calculate Button
I am having trouble with figuring a way to set my loop up to reset values of the different coin values. Example, when I put in 78, and click calculate, it tells you how much of each coin would be given back. My problem is that I set it up and run it, but when I put different values in back to back to calculate, some of the fields don't reset. I just need some ideas or logic behind what I need to do.
Code: var change_out = function(){ do { var money = document.getElementById("cents").value; if (money >= 25) { var quarters = parseInt(money / 25); var foo = parseInt(money - (quarters * 25)); document.getElementById("quarters").value = quarters; if (foo >= 10) { var left = parseInt(foo / 10); var wow = parseInt(foo - (left * 10)); document.getElementById("dimes").value = left; if(wow==0)return; if (wow >= 5) { var dumb = parseInt(wow / 5); var pop = parseInt(wow - (dumb * 5)); document.getElementById("nickels").value = dumb; document.getElementById("pennies").value = pop; }else{document.getElementById("pennies").value = wow;} }else if (foo >= 5){ var dumb = parseInt(foo / 5); var pop = parseInt(foo - (dumb * 5)); document.getElementById("nickels").value = dumb; document.getElementById("pennies").value = pop; }else{document.getElementById("pennies").value = foo;} }else if (money >= 10){ var left = parseInt(money / 10); var wow = parseInt(money - (left * 10)); document.getElementById("dimes").value = left; if (wow > 5){ var dumb = parseInt(wow / 5); var pop = parseInt(wow - (dumb * 5)); document.getElementById("nickels").value = dumb; document.getElementById("pennies").value = pop; document.getElementById("quarters").value = ""; }else{document.getElementById("pennies").value = wow;} }else if (money >= 5){ var dumb = parseInt(money / 5); var pop = parseInt(money - (dumb * 5)); document.getElementById("nickels").value = dumb; document.getElementById("pennies").value = pop; document.getElementById("quarters").value = ""; document.getElementById("dimes").value = ""; }else{ document.getElementById("pennies").value = money; document.getElementById("quarters").value = ""; document.getElementById("dimes").value = ""; document.getElementById("nickels").value = ""; } }while(isNaN(money))} Similar TutorialsI have a page where a user can select (via check boxes) several categories. Each category is related to a set of possible options (radio buttons) that have numeric values. When one of the options (radio button) is selected, the amount will appear in a text box (input type="text"). The numeric value in the text box will update depending on what category options are selected. However, when the checkbox is deselected, the radio boxes in the <div> are not displayed and I need to remove (reset) the radio button values from the value seen in the text box. Here are some snippets to hopefully expound on what I would like to do. Code: <script type="text/javascript"> var amountNotice = 0; function notice(options) { amountNotice = parseInt(options); calculateTotal(); } function calculateTotal() { totalAmount = amountNotice; document.getElementById("total").value = totalAmount.toFixed(2); } function toggle(chkbox, group, associatedValues) { var visSetting; if (chkbox.checked == true) document.getElementById(group).style.display = "inline"; else { document.getElementById(group).style.display = "none"; uncheckRadio(associatedValues); } document.getElementById(group).style.display = visSetting; } function uncheckRadio(associatedValues) { for(var i = 0; i < document.getElementById(associatedValues).length; i++) { if (associatedValues[i].checked == true) associatedValues[i].checked == false; } calculateTotal(); } </script> <style type="text/css"> #groupNotice {display: none} </script> . . <input type="button" onClick="calculateTotal()" value="Calculate"><br> <div id="groupNotice"> <b>Required Notice</b>: <input type="radio" name="Note" onClick="notice(this.value)" value="0"> None <input type="radio" name="Note" onClick="notice(this.value)" value="2"> Prior Day ($2) <input type="radio" name="Note" onClick="notice(this.value)" value="2"> Prior Call ($2)<br> </div> <form name="CostEstimate" method="post" action="calculator.php"> <input type="checkbox" onclick="toggle(this, 'groupNotice', 'Note'); display('groupNotice','inline')" name="Notice" value=""> Notice </form> Everything works except for my uncheckRadio function - not sure if I am identifying the elements correctly, or if I need a totally new approach. My thinking is that the function must be accessed by the checkbox onClick call. Previously I had tried calling uncheckRadio from the notice function before I recognized is was not an appropriate location. Any assistance is greatly appreciated. - c So I need some help with figuring out how to reset both my text boxes when I click a different radio button so that I can give another value in the textbox area. I am trying to do it without a reset button. Any helpful ideas? I am just confused with the process of resetting the values of both the text boxes in the code.Hmmm......lol I feel like the answer is to put it inline in the <input> tag... Code: <body> <div id="content"> <h1>Convert temperature</h1> <input type="radio" name="conversion_type" id="to_celcius" onclick="document.getElementById('degrees_celcius').disabled=this.checked;" />From Fahrenheit to Celcius<br /> <input type="radio" name="conversion_type" id="to_fahrenheit" onclick="document.getElementById('degrees_fahrenheit').disabled=this.checked;" />From Celcius to Fahrenheit<br /> <br /> <label>Degrees Fahrenheit:</label> <input type="text" id="degrees_fahrenheit" class="disabled" /><br /> <label>Degrees Celcius:</label> <input type="text" id="degrees_celcius" class="disabled"/><br /> <br /> <input type="button" id="convert" value="Convert" /><br /> <br /> </div> </body> Hello all. Complete newbie to this and to be quite honest, completely out of my depth. Ok, I have the following set up on my page - the page essentially uses three different search methods to bring back data in a gridview. 1. A cascading drop down list (ddlBuyer, ddlSub, ddlProd) and an associated radio button radBuyer. 2. An autocomplete textbox (tbxProdAC) that sources product information and an associated radio button (radProd) 3. A text box whereby users specify the number of products they wish to see and (txtHowMany) a subsequent sub category radio button list that breaks the products down further (radTopx) What I would like to do is essentially make the page so that a user can only user one of the above methods and the radio is focused according to what the user first specifies. For example, if they wish to use the ddl method, they should click ddlBuyer, ddlSub and ddlProd and the focus is placed upon the radBuyer. Along side of this, any information that may have been entered into tbxProdAC or txtHowMany is cleared. Alternatviely, should a user use the drop down method then wish to use the third method specified above, once a user clicks in txtHowMany, the ddl should revert back to their original values. I would like to achieve this in the c# code behind and I currently have the following code on my page load event/ I have got to the point where I am going round in circles (mainly because I don't know what I am doing!) so I would appreciate a few pointers. Code: ddlProd.Attributes.Add("onchange", "return SetRadioFocus('" + radBuyer.ClientID + "');"); radTopx.Attributes.Add("onclick", "return SetRadioFocus('" + radTopx.SelectedItem + "');"); tbxProdAC.Attributes.Add("onclick", "return SetRadioFocus('" + radProd.ClientID + "');"); ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", @" function SetRadioFocus(target) { document.getElementById(target).checked = true; }" , true); If someone can help me, I would be extremely grateful and it would save me from smashing my head further into my desk. Please excuse my ignorance, brand spanking new to this and feeling more than a little thick. Hi.I have found this nice code through forum.Now I want to modify it a little bit.But dont know how to It calculates amount column value by multiplying quantity to amount.i.e. amount=qty*rate and gross total is sum of all the array elements in amount.Here I want to add two more columns viz vat% and vat amount.Simply it will be amount*vat% / 100.Can anyone please tell me how I can do that?Other thing is, is it possible to separate the 5% vat and 12.5% vat values and display the total of them in respective column? Here is the link for reference : http://kavisandeepdwivedi.com/forum.php Please go through the code below and help me out Code: <html> <head> <script type="text/javascript"> function tot(elem) { var d=document.getElementById("total").value; var total=Number(d); var e=document.getElementById("vat5").value; var vat5=Number(e); var f=document.getElementById("vat12_5").value; var vat12_5=Number(f); var g=document.getElementById("cash_discount").value; var cash_discount=Number(g); var h=(total+vat5+vat12_5)-cash_discount; document.getElementById("grand_total").value = h; } var total = 0; function getValues() { var qty = 0; var rate = 0; var obj = document.getElementsByTagName("input"); for(var i=0; i<obj.length; i++){ if(obj[i].name == "qty[]"){var qty = obj[i].value;} if(obj[i].name == "rate[]"){var rate = obj[i].value;} if(obj[i].name == "amt[]"){ if(qty > 0 && rate > 0){obj[i].value = qty*rate;total+=(obj[i].value*1);} else{obj[i].value = 0;total+=(obj[i].value*1);} } } document.getElementById("total").value = total*1; total=0; } </script> <script type="text/javascript"> function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i<colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; //alert(newcell.childNodes); switch(newcell.childNodes[0].type) { case "text": newcell.childNodes[0].value = ""; break; case "checkbox": newcell.childNodes[0].checked = false; break; case "select-one": newcell.childNodes[0].selectedIndex = 0; break; } } } function deleteRow(tableID) { try { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if (null != chkbox && true == chkbox.checked) { if (rowCount <= 1) { alert("Cannot delete all the rows."); break; } table.deleteRow(i); rowCount--; i--; } } } catch(e) { alert(e); } getValues(); } </script> </head> <body> <form name="gr" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" onSubmit="return validateForm(this)"> <tr> <td class="forhead" style="white-space:nowrap;"><input type="button" value="Add Row" onClick="addRow('dataTable')" > <input type="button" value="Delete Row" onClick="deleteRow('dataTable')" ></td> <table width="38%" align="center" cellpadding="0" cellspacing="0" class="normal-text" border="0"> <td width="20"></td> <td width="80" class="forhead" style="white-space:nowrap;">Qty</td> <td width="80" class="forhead" style="white-space:nowrap;">Rate</td> <td width="80" class="forhead" style="white-space:nowrap;">Amount</td> <td width="80" class="forhead" style="white-space:nowrap;">Vat</td> <td width="80" class="forhead" style="white-space:nowrap;">Vat Amount</td> </tr> </table> <table border="0" id="dataTable" width="38%" align="center" cellpadding="0" cellspacing="0" class="normal-text"> <tr> <td class="forhead" style="white-space:nowrap;" width="20"><input type="checkbox" name="chk[]"/></td> <td class="forhead" style="white-space:nowrap;" width="80"><input type="text" name="qty[]" onkeyup="getValues()" style="width:80px;" onBlur=""></td> <td class="forhead" style="white-space:nowrap;" width="80"><input type="text" name="rate[]" onKeyUp="getValues()" style="width:80px;" value=""></td> <td class="forhead" style="white-space:nowrap;" width="80"><input type="text" name="amt[]" style="width:80px;" onKeyUp="getValues()"></td> <td width="80" align="right" class="forhead" style="white-space:nowrap;"> <select name="vat[]" style="width:80px" onChange="getValues()"> <option value="0">Select</option> <option value="5">5</option> <option value="12.5">12.5</option> </select> </td> <td class="forhead" style="white-space:nowrap;" width="80"><input type="text" name="vat_amt[]" style="width:80px;"></td> </tr> </table> <table width="38%" align="center" cellpadding="0" cellspacing="0" class="normal-text" border="0"> <tr> <td width="20" class="forhead" style="white-space:nowrap;"> </td> <td width="80" class="forhead" style="white-space:nowrap;">Gross Total:</td> <td width="80" class="forhead" style="white-space:nowrap;"> </td> <td width="80" class="forhead" style="white-space:nowrap;"> </td> <td width="80" class="forhead" style="white-space:nowrap;"> </td> <td width="80" class="forhead" style="white-space:nowrap;"><input type="text" id="total" name="total[]" style="width:80px;" value=""></td> </tr> <tr> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;">Vat 5%:</td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"><input type="text" name="vat5[]" id="vat5" style="width:80px;"></td> </tr> <tr> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;">Vat 12.5%:</td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"><input type="text" name="vat12_5[]" id="vat12_5" style="width:80px;"></td> </tr> <tr> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;">Cash Dis :</td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"><input type="text" id="cash_discount" name="cash_discount[]" style="width:80px;" value=""></td> </tr> <tr> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;">Total :</td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"> </td> <td class="forhead" style="white-space:nowrap;"><input type="text" name="grand_total" id="grand_total" onKeyUp="tot()" style="width:80px;"></td> </tr> <tr> <td align="center" colspan="6"> <input name="Submit" type="submit" value="Save" style="text-decoration:none"/> <input type="reset" value="Cancel" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'];?>'"> </td> </tr> </table> </td> </tr> </table> </td> </tr> </form> </body> </html> I have the following code working with the checkbox options but once I added a drop down menu with values, it doesn't calculate it. I've done some different things to try to add the drop down to the function but nothing would work that I've tried so far. I have it setup so when a box is unchecked, that option is taken off the price, the drop down should do the same to switch between the options price. Thanks for the help! Code: <script language="javascript"> totalOptions = 0; function calculateTotalOptions(thisCheckbox){ if (thisCheckbox.checked) { totalOptions += parseFloat(thisCheckbox.value); } else { totalOptions -= parseFloat(thisCheckbox.value); } document.getElementById("totalOptions").value = "$" + totalOptions + ".00"; } </script> <form name="Options" > <table width="765" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="8" align="center" bgcolor="#FFFFFF">Please select which model you would like to price and then add your optional equipment.</td> <td width="4" align="center" bgcolor="#FFFFFF"> </td> <td width="4" align="center" bgcolor="#FFFFFF"> </td> <td width="4" align="center" bgcolor="#FFFFFF"> </td> </tr> <tr> <td colspan="3" align="center" bgcolor="#FFFFFF"><strong>Available on these models</strong></td> <td width="85" align="center" bgcolor="#FFFFFF">Most Popular Options</td> <td width="97" align="center" bgcolor="#FFFFFF">Option Code</td> <td width="192" align="center" bgcolor="#FFFFFF"><strong>Optional Equipment</strong></td> <td width="61" align="center" bgcolor="#FFFFFF"><strong>Price</strong></td> <td width="149" align="center" bgcolor="#FFFFFF"><strong>Add Option</strong></td> </tr> <tr> <td width="58" align="center"><p><strong>SR 125<br /> </strong></p></td> <td width="58" align="center"><p><strong>SR 225<br /> </strong></p></td> <td width="58" align="center"><p><strong>SR 325<br /> </strong></p></td> <td colspan="5" align="right"><strong>Select Base Model: </strong> <select name="model" id="model"> <option value="0.00" selected onclick="calculateTotalOptions(this);">--------</option> <option value="-6995.00" onclick="calculateTotalOptions(this);">SR 125 Standard</option> <option value="-7495.00" onclick="calculateTotalOptions(this);">SR 125 H.D.</option> <option value="7995.00" onclick="calculateTotalOptions(this);">SR 125 S.D.</option> <option value="8495.00" onclick="calculateTotalOptions(this);">SR 225 Standard</option> <option value="8995.00" onclick="calculateTotalOptions(this);">SR 225 H.D.</option> <option value="9595.00" onclick="calculateTotalOptions(this);">SR 225 S.D.</option> <option value="9995.00" onclick="calculateTotalOptions(this);">SR 325 Standard</option> <option value="10495.00" onclick="calculateTotalOptions(this);">SR 325 H.D.</option> <option value="10995.00" onclick="calculateTotalOptions(this);">SR 325 S.D.</option> </select></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF">SR-ES</td> <td bgcolor="#FFFFFF">•Electric start </td> <td bgcolor="#FFFFFF">$345.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="345.00" onclick="calculateTotalOptions(this);"> </td> </tr> <tr> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"> </td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td>SR-OCP</td> <td>•Operator convience package; includes tach, hour, lube meter, hydraulic pressure gauge and bottle holder</td> <td>$125.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="125.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-EZM</td> </table></td> <td bgcolor="#FFFFFF">•EZ maintance hydraulic package; includes temperature and fill sight guage and quickdrain ball valve</td> <td bgcolor="#FFFFFF">$100.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="100.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"> </td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-6W</td> </table></td> <td>•Six way wedge with on board storage</td> <td>$495.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="495.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-JLL</td> </table></td> <td bgcolor="#FFFFFF">•Jointed log lift</td> <td bgcolor="#FFFFFF">$495.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="495.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"> </td> <td align="center"> </td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-SEGTR</td> </table></td> <td>•Segmented tire for spotting includes spotting hitch</td> <td>$350.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="350.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"> </td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-MGST</td> </table></td> <td bgcolor="#FFFFFF">•Motor guard with saddle for segmented tire</td> <td bgcolor="#FFFFFF">$95.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="95.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center"><p><img src="dot.png" alt="" width="11" height="11" /></p></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"> </td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-MG</td> </table></td> <td>•Motor guard w/o saddle</td> <td>$75.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="75.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-SPRTR</td> </table></td> <td bgcolor="#FFFFFF">•Spare tire and holder</td> <td bgcolor="#FFFFFF">$250.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="250.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td> </td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-HOC</td> </table></td> <td>•Hydraulic oil cooler</td> <td>$795.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="795.00" onclick="calculateTotalOptions(this);"> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-GRLP</td> </table></td> <td bgcolor="#FFFFFF">•Grip Rightâ„¢ log points (each additional point)</td> <td bgcolor="#FFFFFF">$20.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="20.00" onclick="calculateTotalOptions(this);"> </td> </tr> <tr> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td> </td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-HDF</td> </table></td> <td>•Heavy duty fenders</td> <td>$145.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="145.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center" bgcolor="#FFFFFF"><p><img src="dot.png" alt="" width="11" height="11" /></p></td> <td align="center" bgcolor="#FFFFFF"><img src="dot.png" alt="" width="11" height="11" /></td> <td bgcolor="#FFFFFF"> </td> <td bgcolor="#FFFFFF"><table cellspacing="0" cellpadding="0"> <td width="127">SR-LP</td> </table></td> <td bgcolor="#FFFFFF">•Light package</td> <td bgcolor="#FFFFFF">$195.00</td> <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="t1" id="t1" value="195.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td align="center"><p><img src="dot.png" alt="" width="11" height="11" /></p></td> <td align="center"><img src="dot.png" alt="" width="11" height="11" /></td> <td> </td> <td><table cellspacing="0" cellpadding="0"> <td width="127">SR-38LO</td> </table></td> <td>•38" log opening *includes 2 1/2" cylinder rod </td> <td>$995.00</td> <td align="center"><input type="checkbox" name="t1" id="t1" value="995.00" onclick="calculateTotalOptions(this);"></td> </tr> <tr> <td colspan="8" align="center" bgcolor="#FFFFFF"> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td> </td> <td> </td> <td> </td> <td><strong>TOTAL:</strong></td> <td><input type="text" id="totalOptions" readonly> </td> </tr> </table> </form> hye.. i'm trying to calculate value of balance by substract cash to total. But nothing happen. here is my code: Code: <script type="text/javascript"> function substract(){ { document.calculate.Cash.value = ZA; document.calculate.Total.value = Z1; balance(); } function balance(){ AAA = document.calculate.Balance; AAA.value = (ZA-Z1).toFixed(2); } </script> </head> <body style="background-color: #99FF99"> <?php // if there are any errors, display them if ($error != 'Unable to update') { echo '<div style="padding:12px; border:1px solid purple; color:red; font-weight: bold; text-align: center; font-size: medium; ">'.$error.'</div>'; } ?> <form action="" method="post" name="calculate" style="width: 1320px; "> <div class="style1"> <input type="hidden" name="CustID" value="<?php echo $CustID; ?>"> <input type="hidden" name="Total" value="<?php echo $Total; ?>"> <input type="hidden" name="TableID" value="<?php echo $TableID; ?>"> <div class="style5" style="width: 820px; height: 148px; margin-left: auto; margin-right: auto;"> <p class="style9"> </p> <p class="style17"><span class="style19">CUSTOMER </span> <strong> <span class="style19">ID:</span></strong> <strong> <?php echo $CustID; ?> </strong></p> <table style="width: 35%; height: 185px; margin-left: auto; margin-right: auto;" class="style15"> <tr> <td class="style11" style="width: 111px; height: 30px;"><strong>Table ID : </strong></td> <td style="height: 30px; width: 169px;" class="style18"><strong><?php echo $TableID; ?></strong></td> </tr> <tr> <td class="style1" style="width: 111px; height: 20px;"></td> <td style="height: 20px; width: 169px;" class="style1"></td> </tr> <tr> <td class="style16" style="width: 111px; height: 30px;"><strong>Total : </strong></td> <td style="height: 30px; width: 169px;" class="style18"><strong> RM<?php echo $Total; ?> </strong></td> </tr> <tr> <td class="style1" style="width: 111px; height: 20px;"></td> <td style="height: 20px; width: 169px;" class="style1"></td> </tr> <tr> <td class="style16" style="width: 111px; height: 30px;"><strong>Cash : </strong></td> <td style="height: 30px; width: 169px;" class="style1"> <strong> <span class="style20">RM</span> <input type="text" name="Cash" id="Cash" class="style17" style="width: 120px"></strong></td> </tr> <tr> <td class="style1" style="width: 111px; height: 20px;"></td> <td style="height: 20px; width: 169px;" class="style1"></td> </tr> <tr> <td class="style16" style="width: 111px; "><strong>Balance : </strong></td> <td style="width: 169px;" class="style1"><strong> <span class="style20">RM</span> <input type="text" name="Balance" id="Balance" value="0.00" class="style17" style="width: 120px"></strong></td> </tr> </table> <p class="style5"><strong> <input class="style3" name="calculate" type="button" onclick="substract()" value="Calculate"> <input class="style3" name="submit" type="submit" value="Done"></strong> </div> </div> </form> Need help please asap. It might be simple but i couldn't work out the script. help! ---------------- Formfield.anzahl1 = number entered by customer Formfield.Price1 = Ergebnisfeld1 e.g. Anzahl1= 1 Price = 270 *if Anzahl1 = 2 then Price = 270*2 I need to do this for two form option. 2nd field would be as follows Formfield.Anzahl2= number entered by customer Formfield.Price2 = Ergebnisfeld2 Then Formfield.Total = Ergebnisfeld1 + Ergebnisfeld2 ------------------- How can I convert these above to javascript? hey all, I have had a go at another calculator I am making and got stuck. I want to use the F value determined by the first toggle button in the calculation. I dont understand why the calculation wont work as it is stated in the if/else statement. Any suggestions what i am doing wrong? here is the code: Code: <script type="text/javascript"> function toggle(btn) { var radioSelection = btn.value; if (radioSelection == "PO") { var F = 0.7; } else { var F = 1; } } function toggle(btn) { var radioSelection = btn.value; var weightInput = document.getElementById("weightRow"); var CPsInput = document.getElementById("CPsRow"); var creInput = document.getElementById("creRow"); var CHFInput = document.getElementById("CHFrow"); var LDOutput = document.getElementById("LDrow"); var MDOutput = document.getElementById("MDrow"); if (radioSelection == "MD") { weightInput.style.display = "none"; CPsInput.style.display = "block"; creInput.style.display = "block"; CHFInput.style.display = "block"; MDOutput.style.display = "block"; LDOutput.style.display = "none"; } else { weightInput.style.display = "block"; CPsInput.style.display = "none"; creInput.style.display = "none"; CHFInput.style.display = "none"; MDOutput.style.display = "none"; LDOutput.style.display = "block"; } } function calculate() { var LD = 1; var MD = 1; var VD = 7.3; var CPd = 1.5; var Cl = 1; var S = 1; var T = 1; var weight = document.getElementById("weight").value - 0; var CHD = document.getElementById("CHD").value; var creatinine = document.getElementById("creatinine").value - 0; var CPs = document.getElementById("CPs").value -0; if (CHD == "Y") { Cl = 23 + (0.88 * creatinine); LD = (VD * weight * CPd) / (S * F); MD = (CPs * Cl * T) / (F * S); } else { Cl = 57 + (1.02 * creatinine); LD = (VD * weight * CPd) / (S * F); MD = (CPs * Cl * T) / (F * S); } var LD = Math.floor(LD / 125) * 125 var MD = Math.floor(MD / 62.5) * 62.5 document.getElementById('LD').innerHTML = LD + " micrograms - NOTE: if loading dose is above 500micrograms, give in divided doses of no more than 500micrograms at one time"; document.getElementById('MD').innerHTML = MD + " micrograms"; document.getElementById('F').innerHTML = F; document.getElementById('S').innerHTML = S; } </script> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <strong>Please select the route to be used for administering digoxin:</strong><br /> <input type="radio" name="route" value="PO" checked onclick="toggle(this);">Oral<br /> <input type="radio" name="route" value="IV" onclick="toggle(this);">Intravenous<br /> <br /> <br /> <strong>Now select whether you wish to calculate a Loading or Maintenance dose:</strong><br /> <input type="radio" name="dosage" value="LD" checked onclick="toggle(this);">Loading Dose<br /> <input type="radio" name="dosage" value="MD" onclick="toggle(this);">Maintenance Dose<br /> <br /> <br /> <table> <tr id="CPsRow" style="display:none"> <td class="style19">Patient's Digoxin Level</td><td class="style17"><input id='CPs' value=""/> micrograms/L </td><td> <ul> <li>Ensure that the level has been taken at least 6 hours post dose. Time to steady state is 10-14 days after initiation/dose change (if renal function is normal).</li> </ul> </td> </tr> <tr id="weightRow" style="display:block"> <td class="style19">Weight</td><td class="style17"><input id='weight' value=""/> kg</td> </tr> <tr id="creRow" style="display:none"> <td class="style19">Creatinine</td><td class="style17"><input id='creatinine'/> mmol/L</td> </tr> <tr id ="CHFrow" style="display:none"> <td class="style19">Chronic Heart Failure </td><td class="style18"><select id='CHD'> <option value="N">No</option><option value="Y">Yes</option></select></td> </tr> </table><br /> <input type="button" onclick="calculate()" value="Calculate!"/><input id="Reset" type="reset" value="Reset" /> <br /> <br /> <br /> <br /> <table> <tr id="LDrow" style="display:block"><td><strong>Loading dose: </strong> </td><td id='LD' /></td></tr> <tr id="MDrow" style="display:none"><td><strong>Maintenance dose: </strong> </td><td id='MD' /></td></tr> <tr><td><strong>Bioavailability factor used: </strong></td><td id='F' /></td></tr> <tr><td><strong>Salt factor used: </strong> </td><td id='S' /></td></tr> </table> I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. I need to figure out how to connect it to the function. Can someone please point out where I am going wrong? I am very new at this and am woundering what I am doing wrong with my code. This is homework, I am not looking for the answer I just need someone to direct me in the right way.Thanx Here is my Code: I need this code to calculate the sales tax when you hit the submit button and I can't get it to work. Can someone please point out where I am going wrong? Code: <script type="text/javascript"> /*<![CDATA [*/ //Shipping & handling fee function calculateShipping() { var num = new Number(price); //This will add $1.50 to any purchases that are less than or equal to $25.00. if (num <= 25){ return 1.5; //Here 10% will be added to any purchase that is greater than $25.00 but do not inlcude the $1.50 fee. } else{ return num * 10 / 100; } } window.alert("Your total is $" + total + ".") /* ]]> */ </script> </head> <body> <h1>Enter Purchase Price Here</h1> <script type="text/javascript"> /* <![CDATA[ */ document.write(parseFloat"); if(price <=25.00){var shipping=1.50} else{var shipping=price*(10/100)}; var total=(price+shipping).toFixed(2); /* ]]> */ </script> <form id="btncalcprice" action="submit-form.php"> <input type='text' name='query'> </form> <form> <input type="button" value="Submit" onClick="alert('YOUR total is $'); return true"> </form> </body> Hello! I wan't to know what is the best way for hitting a given URL whit javascript. I just need that that page hitted know that it was hitted. Tanks! Hi Guys, Hope you can help. My sister has made a web site with a web counter and want to get the counter up by a few hundered. She cannot alter the number manually. Is there a script i can use to get the web counter up by a few hundred? So in other words a web page with java on so it gones on to her site (adds a count) leave it Or refresh it then reload it. Hope i have made my self Clear. thanx, Or even i culd run a web page which loads the page, closes it and load it again. Thanx. Lusa.. I have 4 rows in a table. Each row consist of 4 radio buttons. Each radio button per row has different values in it but has the same name (group) ex: <input type="radio" name="a" value="1"> <input type="radio" name="a" value="2"> <input type="radio" name="a" value="3"> <input type="radio" name="a" value="4"> <input type="radio" name="b" value="1"> <input type="radio" name="b" value="2"> <input type="radio" name="b" value="3"> <input type="radio" name="b" value="4"> and so on.. If I click radio button A with value 2, I want to output the total at the bottom as "2".. Also, if I click radio button B with value 3, I want to output the total of A and B as 5 and so on.. How can I automatically calculate the answer based on which radio button was click? update: I got my answer from this site: http://stackoverflow.com/questions/1...s-using-jquery I have the following files in the same directory. I can get index.php displayed but when I enter anything and hit submit I cannot get the or die message to display. I have the files in the c:\xampp\htdocs\ folder and am using http://localhost/index.php from a browser. index.php: 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 content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Username</title> </head> <body> <form action="index.php" method="POST"> Username: <input type="text" name="username"><br> <!--input is text, variable is 'username'--> Password: <input type="password" name="password"> <!--input is password, a type of text, variable is password --> <input type="submit" value="Log in"> <!--input is submit, which is a button, and text on button will read 'Log in'--> </form> </body> </html> login.php: Code: <?php $username = $POST['username']; // setting php var '$username' to equal 'username' from the index.php page (POST method) $password = $POST['password']; if ($username&&$password) //are true { $connect = mysql_connect("localhost", "root", "") //creates connection to database, we're creating a var called or die ("Couldn't connect"); //'$connect' and now we have 3 var's. 'localhost' is the host. 'root' is the //username. mysql_select_db("phplogin") or die("Couldn't find db"); } else die("Please enter a username and a password!"); ?> Hello I am very new to Java Script. I am working on a website which requires me to use it. The site is selling items that are priced depending on the size. There are 6 fixed sizes for the width and the length can come in any size 1 through 200. So that will be user input on the length and radio buttons on the width. I am trying to have the user put in the length and click a radio button for width and then calculate the price by multiplying them. I am trying to get 1 price to display right now just to test it but I can't figure out why it isn't working. Again I am fairly new at this so there might be multiple problems with my code. Thanks in advance for the help. Code: <script type = "text/javascript"> function buttoncheck(){ var selection1 = document.menu.selection; if (selection1 == 60) {choice1()} if (selection1 == 50) {choice2()} if (selection1 == 25) {choice3()} if (selection1 == 10) {choice4()} if (selection1 == 4) {choice5()} if (selection1 == 2) {choice6()} function choice1(){ var len = Number(document.getElementById("length").value) || 0; var area1 = selection1 * len; var cost = 0; if (area1 == 60) { cost = 60} return cost; document.getElementById("TotalCost").innerHTML = "$" + cost.toFixed(2); } Code: <h4 class="auto-style3">Pricing Calculator:</h4> <p> <form method="post"> <div class="auto-style1"> <span class="auto-style2">LENGTH:</span> <input name="length" type="text" id="length" /><br /> </form> <div class="auto-style1"> <form name="menu"> <input type="radio" value="60" name="selection">60 inch</input> <input type="radio" value="50" name="selection">50 inch</input> <input type="radio" value="25" name="selection">25 inch</input> <input type="radio" value="10" name="selection">10 inch</input> <input type="radio" value="4" name="selection">4 inch label</input> <input type="radio" value="2" name="selection">2 inch label</input> </form> </div> <p class="auto-style1"> <input type="button" value="Calculate" onClick="buttoncheck()" </p> </p> <p> </p> <span id="TotalCost"></span><script type = "text/javascript"> document.getElementById("TotalCost").innerHTML = "Total cost is $" + cost.toFixed(2); Hey javascript newbie, Im trying to figure out how to add different radio if its selected or not example: Radio_Button1 value="5": Selected Radio_Button2 value="15": Not Selected Radio_Button3 value="25": Selected Radio_Button4 value="35": Selected var addingitup = ??? and im lost???? I have some asp:radiobutton lists that need to update a label with the sum of their values each time a user selects a new value. I am brand new to javascripting and would like some insight on how to get this done. I have inserted my code below. Code: <asp:Label runat="server" Text="Greeting:" /> <asp:Label runat="server" ForeColor="Red" ID="lbl_GreetingScore" Text="0" /> <asp:RadioButtonList ID="rdb1_1" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Selected="True" Text="N/A" Value="4" /> <asp:ListItem Text="Yes" Value="4" /> <asp:ListItem Text="No" Value="0" /> </asp:RadioButtonList> I am using ASP validators and I have a contact form. I want to be able to have a phone and email radio button group. The email textbox also has a RegularExpressionValidator If the phone item is selected then I want the validation to be enabled on the phone text box making it mandatory while the email text box isn't, and if they choose the email as the contact it will be reversed. I want to be able to do this without having to do a postback. I already have the logic on the code behind and the enquiry object. also I am fairly new to javascript so I have been using mostly jQuery as easier to implement |