JavaScript - Ipt Calculation (calculate A Percentage Of A Figure)
Hi,
I am fairly new to this so please bare with me. I have a php page that uses Javascript (I think) to calculate the percentage Insurance Premium Tax (IPT field) of a total. I have located where the calculation occurs and can see that it take the total of a predefined amount and divides it by 21 to give me the 5% IPT tax. IPT has risen in the UK today to 6% so I need to know what I need to change the 21 to to give me an accurate IPT calculation. Here's a snippet of the code. Can anyone help please? Is it 17.65? PHP Code: //////////////////////////////////////////// // Motor Bike Calculations //////////////////////////////////////////// $p = 3; $q = 0; while ($p < 6){ $base_array = mysql_fetch_row($result4); // Motor Bikes $risk_code = 2; $ap = (0 + ($p)); $ipt_rate = $ipt_main; $monthly_total = $pricing_row[$ap]; // Calculate IPT $ipt_percentage = $monthly_total / 21; $monthly_ipt = $ipt_percentage; $base_cost = $base_array[0] + $dealer_loading; $base_final = $base_cost; $profit = $monthly_total - $base_cost - $monthly_ipt; $monthly_total = number_format($monthly_total, 2, '.', ''); $monthly_ipt = number_format($monthly_ipt, 2, '.', ''); $base_final = number_format($base_final, 2, '.', ''); $profit = number_format($profit, 2, '.', ''); echo ' <tr align="center" bgcolor="#FFDDFF"> <td>'; if ($p == 3) { echo (''); } elseif ($p == 4) { echo ('UK'); } elseif ($p == 5) { echo ('UK & European'); } echo '</td> <td> <input name="'; if ($p == 3) { echo ('comprehensive_plus_'.$risk_code); } elseif ($p == 4) { echo ('comprehensive_'.$risk_code); } elseif ($p == 5) { echo ('driveline_plus_'.$risk_code); } echo '" type="text" value="'.$pricing_row[$ap].'" size="6" maxlength="6" class="smallinfo"> </td> <td>'.$monthly_ipt.'</td> <td>'.$base_final.'</td> <td>'.$profit.'</td> </tr>'; $q++; $p++; } Similar TutorialsI am having issues with my code... below are the instructions. "prompt the user for the cost of a purchase and the sales tax rate as a percentage. Calculate the tax amount and the total cost. Display all 4 values in the document" I am having some real issues with the tax rate percentage, it keeps showing as a decimal, and does not calculate correctly. Any help is highly appreciated. Thanks so much! var cost = prompt("What is the cost of your purchase?", "") document.write("Return Value: "+cost,("<br />")); var tax = prompt("What is your tax rate percentage?", "") document.write("Return Value: "+tax,("<br />")); var salestax= cost * tax document.write("Return Value: "+salestax,("<br />")); var total = eval(cost) + salestax document.write(total, ("<br />")); Hi everyone Dont know if it can be done but.... I am using the percentage calculator Code: <SCRIPT language=JavaScript> <!-- //Script by Tom Richardson Jr. //If you have any questions, e-mail me at gooftroop@geocities.com //or visit mt web site at http://home.rmci.net/gooftroop //For this script and more, visit http://javascriptkit.com function perc1() { a = document.form1.a.value/100; b = a*document.form1.b.value; document.form1.total1.value = b } function perc2() { a = document.form1.c.value; b = document.form1.d.value; c = a/b; d = c*100; document.form1.total2.value = d } //--> </SCRIPT> <FORM name=form1> <TABLE cellSpacing=1 cellPadding=1 border=1> <TBODY> <TR> <TD align=middle colSpan=3><B><FONT size=4>Percentage Calculator</FONT></B> </TD> <TR> <TD>What is <INPUT size=5 name=a> % of <INPUT size=5 name=b>?</TD> <TD>Answer: <INPUT maxLength=40 size=5 name=total1></TD> <TD><INPUT onclick=perc1() type=button value=Calculate></TD> <TR> <TD><INPUT size=5 name=c> is what percent of <INPUT size=5 name=d>?</TD> <TD>Answer: <INPUT size=5 name=total2> %</TD> <TD><INPUT onclick=perc2() type=button value=Calculate></TD> <TR> <TD align=middle colSpan=3><INPUT type=reset value=Reset></TD></TR></TBODY></TABLE></FORM> Does anyone know how I could change the answer to a percentage bar instead of the numeric answer ? or change the colour of the answer to say red or green depending on the value ? Many thanks Donna I am using a JavaScript price calculator. Right now it does everything I need except for one thing. If you look at the "type" field, they can choose either woven or printed. Right now, if they choose "woven" it adds 6 cents to to the total as you can see in this portion of the code: if (theForm.select.value=="woven") { priceeach+=0.06; Rather than 0.06, how do I get it to add a percentage--say 20% The form is located he http://goo.gl/YlJWo Thank you! I am having an issue with converting my decimal to a percentage... any suggestions? Thanks - it's probably an easy solution, but I am lost below is my code (cost * .06) is where the issue is - Thanks! var cost = prompt("What is the cost of your purchase?", "") document.write("Return Value: "+cost,("<br />")); var salestax = cost * .06 document.write("Return Value: "+salestax,("<br />")); var total = cost + salestax document.write(cost + salestax); Hi. Can someone please tell me if a bent percentage silder is possible (something like this http://www.codingforums.com/showthread.php?t=173255 only I want it to be bent about 330 degrees, and I wouldn't want to link to another class-I would like to host the entire code on my website)? Also, the reason I want the slider to be bent, is because I would like the slider to be a sort of bent rectangle, and when the user clicks/drags the slider, the rectangle would "fill" to that point (change its background color up to where the mouse is). Thank you. Bye.
Is there a way with Firefox/Chrome to get the actual % used instead of the rendered pixel values? For example I have a table with the following CSS markup Code: #tableFoo : { width : 50%; } In IE to get the percentage set in the CSS file, it is as simple as: Code: var width = tableObj.currentStyle["width"] I am having trouble figuring out a way to get the percentage value with Firefox and Chrome. I am thinking it is not possible other than stylesheet sniffing and ripping out the rules that way which I am not going to do. Thanks, Eric 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. I am trying to create a function or have this work some how where it displays the first number when you make your choice in the first drop down box, which is working so far. In the second drop down box, if any of the answers are chosen except for none, it will take off 10% of the first number. Then add or subtract from there. I just have a problem with creating a function to take off that 10%. Here is the javascript: Code: /* This source is shared under the terms of LGPL 3 www.gnu.org/licenses/lgpl.html You are free to use the code in Commercial or non-commercial projects */ //Set up an associative array //The keys represent the size of the cake //The values represent the cost of the cake i.e A 10" cake cost's $35 var practice_field = new Array(); practice_field["None"]=0; practice_field["Allergy and Immunology"]=4400; practice_field["Endocrinology"]=4400; practice_field["Pathology"]=4400; practice_field["Dermatology"]=4400; practice_field["Geriatrics"]=4400; practice_field["Physical Rehabilitation"]=4400; practice_field["Family Practice"]=6900; practice_field["General Practice"]=6900; practice_field["Internal Medicine"]=6900; practice_field["Oncology"]=6900; practice_field["Oral Surgery"]=6900; practice_field["Radiology"]=6900; practice_field["Gastroenterology"]=6900; practice_field["Infectious Disease"]=6900; practice_field["Nephrology"]=6900; practice_field["Ophthalmology"]=6900; practice_field["Pediatrics"]=6900; practice_field["Urology"]=6900; practice_field["Anesthesiology"]=9000; practice_field["Cosmetic Surgery"]=9000; practice_field["General Surgery"]=9000; practice_field["Neurology"]=9000; practice_field["Otolaryngology"]=9000; practice_field["Plastic Surgery"]=9000; practice_field["Vascular Surgery"]=9000; practice_field["Cardiology"]=9000; practice_field["Emergency Medicine"]=9000; practice_field["Gynecology"]=9000; practice_field["Orthopedic Surgery"]=9000; practice_field["Pain Management"]=9000; practice_field["Pulmonary Surgery"]=9000; practice_field["Neurological Surgery"]=9900; practice_field["Obstetrics"]=9900; //Set up an associative array //The keys represent the filling type //The value represents the cost of the filling i.e. Lemon filling is $5,Dobash filling is $9 //We use this this array when the user selects a filling from the form var society_member= new Array(); society_member["None"]=1; society_member["BCMA"]=0.10; society_member["DCMA"]=0.10; society_member["FOGS"]=0.10; society_member["FNS"]=0.10; society_member["PBCMS"]=0.10; society_member["FSPS"]=0.10; //This function finds the filling price based on the //drop down selection function getPracticeField() { var docPracticeField=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the select id="filling" var selectedPracticeField = theForm.elements["practice"]; //set cakeFilling Price equal to value user chose //For example filling_prices["Lemon".value] would be equal to 5 docPracticeField = practice_field[selectedPracticeField.value]; //finally we return cakeFillingPrice return docPracticeField; } //This function finds the filling price based on the //drop down selection function getSelectedSociety() { var docSelectedSociety=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the select id="filling" var selectedSociety = theForm.elements["society"]; //set cakeFilling Price equal to value user chose //For example filling_prices["Lemon".value] would be equal to 5 docSelectedSociety = society_member[selectedSociety.value]; //finally we return cakeFillingPrice return docSelectedSociety; } //candlesPrice() finds the candles price based on a check box selection function candlesPrice() { var candlePrice=0; //Get a reference to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the checkbox id="includecandles" var includeCandles = theForm.elements["includecandles"]; //If they checked the box set candlePrice to 5 if(includeCandles.checked==true) { candlePrice=5; } //finally we return the candlePrice return candlePrice; } function insciptionPrice() { //This local variable will be used to decide whether or not to charge for the inscription //If the user checked the box this value will be 20 //otherwise it will remain at 0 var inscriptionPrice=0; //Get a refernce to the form id="cakeform" var theForm = document.forms["cakeform"]; //Get a reference to the checkbox id="includeinscription" var includeInscription = theForm.elements["includeinscription"]; //If they checked the box set inscriptionPrice to 20 if(includeInscription.checked==true){ inscriptionPrice=20; } //finally we return the inscriptionPrice return inscriptionPrice; } function calculateTotal() { //Here we get the total price by calling our function //Each function returns a number so by calling them we add the values they return together var cakePrice = getPracticeField() * getSelectedSociety() + candlesPrice() + insciptionPrice(); //display the result var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Price For the Cake $"+cakePrice; } function hideTotal() { var divobj = document.getElementById('totalPrice'); divobj.style.display='none'; } How can i "prompt the user for the sales tax rate as a percentage"? Thanks soooo much for any help! this is what i have so far.... var tax = prompt("What is your tax rate percentage?", "") document.write("Return Value: "+tax,("<br />")); I am trying to customize this scrollbar so that it will fit all screen resolutions and I was wondering how I could do this by somehow customizing the JavaScript files created by Nathan Faubion or if I could do this using other JavaScript variables (var widthPercentage) to change the pixels to percentages? Please let me know what you think. Thank you very much! One of the pages on the website I'm using the JavaScript on: http://www.clintshipley.com/about.html Code: JavaScript file jsScroller.js: //Created by Nathan Faubion http://www.n-son.com/scripts/jsScrolling/ function jsScroller (o, w, h) { var self = this; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } //Private methods this._setPos = function (x, y) { if (x < this.viewableWidth - this.totalWidth) x = this.viewableWidth - this.totalWidth; if (x > 0) x = 0; if (y < this.viewableHeight - this.totalHeight) y = this.viewableHeight - this.totalHeight; if (y > 0) y = 0; this._x = x; this._y = y; with (o.style) { left = this._x +"px"; top = this._y +"px"; } }; //Public Methods this.reset = function () { this.content = o; this.totalHeight = o.offsetHeight; this.totalWidth = o.offsetWidth; this._x = 0; this._y = 0; with (o.style) { left = "0px"; top = "0px"; } }; this.scrollBy = function (x, y) { this._setPos(this._x + x, this._y + y); }; this.scrollTo = function (x, y) { this._setPos(-x, -y); }; this.stopScroll = function () { if (this.scrollTimer) window.clearInterval(this.scrollTimer); }; this.startScroll = function (x, y) { this.stopScroll(); this.scrollTimer = window.setInterval( function(){ self.scrollBy(x, y); }, 40 ); }; this.swapContent = function (c, w, h) { o = c; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } if (w) this.viewableWidth = w; if (h) this.viewableHeight = h; this.reset(); }; //variables this.content = o; this.viewableWidth = w; this.viewableHeight = h; this.totalWidth = o.offsetWidth; this.totalHeight = o.offsetHeight; this.scrollTimer = null; this.reset(); }; JavaScript on HTML page: <script type="text/javascript" src="Scripts/jsScroller.js"></script> <script type="text/javascript" src="Scripts/jsScrollbar.js"></script> <script type="text/javascript"> var scroller = null; var scrollbar = null; window.onload = function () { scroller = new jsScroller(document.getElementById("scroller"), 550, 275); scrollbar = new jsScrollbar (document.getElementById("scrollbar-content"), scroller, false); } </script> Hi. Sort of new to Javascript. I am implementing a zoom in feature, but actually tricking the user as a full screen image is simply being stretched. I plan to apply it to several pages, and don't really fancy working out the pixels for each. I believe that if you simply put width: 150% height 150% it will change the image size relative to the browser. I don't want that, I want it relative to the original image size. Could I do sort of height*1.5 or something? How would I write that if so? Thanks! Code: <script> $('#in').click(function() { $('#drag img').animate({ width: '150%', height: '150%', }, 5000, function() { // Animation complete. }); }); </script> I've started studying JavaScript recently. The following simple scenario from the Russian textbook cannot be implemented on my PC. Code: <HTML> <HEAD> <TITLE>Object Math Example</TITLE> </HEAD> <BODY> <h1>Object Math Example</h1> <p>Насколько случайны числа, полученные генератором случайных чисел? Подсчитаем среднее 5000 случайных чисел.</p> <SCRIPT LANGUAGE="JavaScript"> total = 0; for (i = 0; i<5000; i++) { num = Math.random(); total += num; document.status = "Generated " + i + " numbers"; } average = total / 5000; average = Math.round(average * 1000 / 1000); document.write("<h2>" arithmetic mean of random numbers + average + "</h2>"); </SCRIPT> </BODY> </HTML> I just typed the script char by char. I use Firefox browser, v.3.5.7. The error console does not display any mistakes. Please, explain me what is wrong in the code. Hi everyone, I am new to Javascript and took a class or 2 in college, but need some help. I need to make a calculation for a webpage that will do the following: Client will insert AWG (wire ) Size, then it will derive the correct Circular Mils that the AWG is equal to from an Access Database ( I assume this is the way to set that up or if I can in Javascript itself, thats fine as well ), then Multiply it by the Number of Strands that the Client will also insert. I had this all set up in Visual Basic and working great, and my boss said he does not want it in a pop up box but prefers it on the website itself hence me reverting to Javascript for this. To visualize it Image 2 boxes with AWG and STRANDS that the client will put in, then another box with TOTAL CMA where the answer will pop up after it has multipled by the AWG individual CMA and number of Strands. I have the general idea to set it up, just do not know how to get the Database in there and Code it properly or whatever. I would appreciate any assistance I can get :-) Thanks everyone. The problem that I am facing is my total amount comes out to $102.46 through my calculations on the page. But when it is moved over to PayPal, the value becomes $102.44. I have many more amount that are also either up .2 cents or down .2 cents. I managed to track this down as a rounding issue. Anytime I do the math, it rounds the amount off and gives the total. But since quantity is involved which is done through PayPal, I had to divide my total by the quantity to bring it back to its original amount thus allowing PayPal to multiply the amount by the quantity. I've pulled my hair out on this one. Ay help would be appreciated. Thank you Code: <html> <head> <title>TESTING</title> <script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationCheckbox.js" type="text/javascript"></script> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css"> <link href="SpryAssets/SpryValidationCheckbox.css" rel="stylesheet" type="text/css"> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css"> </head> <td width="95%" align="center" class="TextoImageSpace"><table border="0" cellpadding="0" cellspacing="0" class="TextoImageSpace_center"> <tr> <td align="center"><h2>Pricing</h2> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="price" id="price"> <p>Select amount please.</p> <p> <input type="hidden" name="cmd" value="_xclick" /> State: <br /> <span id="spryselect1"> <!-- selects the state // onclick changes the variables specified values --> <select name="combo0" id="combo_0" onclick="roundNumber(amount2.value, 2);roundNumberTax(tax.value, 2);roundNumberProduct(product.value, 2);roundNumberShipping(shipping.value, 2);roundNumberAmount(amount2.value, 2)" style="width:200px;"> <option selected="selected"> </option> <option value="70">Arizona</option> </select> <span class="selectRequiredMsg"></span></span><br /> Quantity: <br /> <span id="spryselect2"> <!-- selects the quantity // onclick changes the variables specified values --> <select name="combo1" id="combo_1" onclick="roundNumber(amount2.value, 2);roundNumberTax(tax.value, 2);roundNumberProduct(product.value, 2);roundNumberShipping(shipping.value, 2);roundNumberAmount(amount2.value, 2)" style="width:200px;"> <option selected="selected"> </option> <option value="4">4 - $20.95</option> </select> <span class="selectRequiredMsg"></span></span><br /> Product: <br /> <span id="sprytextfield11"> <label> <input type="text" name="product" id="txt_product" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Shipping: <br /> <span id="sprytextfield9"> <label> <input type="text" name="shipping" id="txt_shipping" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Taxes: <br /> <span id="sprytextfield10"> <label> <input type="text" name="tax" id="txt_tax" disabled="disabled" value="" style="width:200px;" /> </label> </span><br /> Total: <span id="sprytextfield8"> <input type="hidden" name="amount" id="txt_price" value="" style="width:200px;" /> </span> <input type="hidden" name="amount3" id="txt_price3" value="" style="width:200px;" /> <br /> <span id="sprytextfield7"> <input type="text" name="amount2" id="txt_price2" disabled="disabled" value="" style="width:200px;" /> </span></p> <hr width="100%" /> <p>Please fill in details.</p> <p> <input type="hidden" name="item_name" value="TEST ITEM" /> <input type="hidden" name="button_subtype" value="products" /> <input type="hidden" name="rm" value="1" /> <input type="hidden" name="return" value="http://www.example.com/" /> <input type="hidden" name="cancel_return" value="http://www.example.com/" /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted" /> <input type="hidden" name="address_override" value="1" /> <input type="hidden" name="shipping" value="0" /> <input type="hidden" name="business" value="wayne@lifelikemedia.ca" /> <input type="hidden" name="quantity" id="quantity" value="1" /> <input type="hidden" name="state" id="state" value="" /> First Name: <br /> <span id="sprytextfield1"> <input type="text" name="first_name" value="TEST" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> Last Name: <br /> <span id="sprytextfield2"> <input type="text" name="last_name" value="TEST" style="width:200px;" /> </span> <br /> Address: <br /> <span id="sprytextfield3"> <input type="text" name="address1" value="1234 TEST STREET" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> City: <br /> <span id="sprytextfield4"> <input name="city" type="text" value="Scottsdale" style="width:200px;" /> <span class="textfieldRequiredMsg"></span></span><br /> ZIP Code: <br /> <span id="sprytextfield5"> <input type="text" name="zip" value="85260" style="width:200px;" /> </span><br /> Country: <br /> <span id="sprytextfield6"> <input name="country" type="text" disabled="disabled" value="US" style="width:200px;" /> </span><br /> <br /> <span id="sprycheckbox1"> <label> <input type="checkbox" name="replacePolicy" id="replacePolicy" /> </label> <span class="checkboxRequiredMsg">Please read policy.</span></span> <a href="#" class="style10" onClick="window.open('replace.html','popup','width=400,height=300,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=50,top=0'); return false">Please read policy.</a><br /> <br /> <input type="image" name="submit" border="0" src="http://www.thinkanddone.com/finance/buynow.jpg" alt="PayPal - The safer, easier way to pay online" /> </p> </form></td> </tr> </table> <script type="text/javascript"> var shipping = document.getElementById("txt_shipping").value; var tax = document.getElementById("txt_tax").value; var product = document.getElementById("txt_product").value; // rounds total amount off function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var v1 = document.getElementById("combo_1").value, v2 = document.getElementById("combo_0").value; var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); var newnumber2 = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.amount2.value = newnumber.toFixed(2); // Output the result to the form field document.price.amount.value = (newnumber2 / v1).toFixed(2); } // rounds tax off function roundNumberTax(rnum, rlength) { // Arguments: number to round, number of decimal places var taxnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.tax.value = taxnumber.toFixed(2); // Output the result to the form field } // rounds product off function roundNumberProduct(rnum, rlength) { // Arguments: number to round, number of decimal places var productnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.product.value = productnumber.toFixed(2); // Output the result to the form field } // rounds shipping off function roundNumberShipping(rnum, rlength) { // Arguments: number to round, number of decimal places var shippingnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.shipping.value = shippingnumber.toFixed(2); // Output the result to the form field } // rounds paypal amount off function roundNumberAmount(rnum, rlength) { // Arguments: number to round, number of decimal places var amountnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); document.price.amount2.value = amountnumber.toFixed(2); // Output the result to the form field } window.onload = function() { var dropChange = function() { // Declaring variables var v1 = document.getElementById("combo_1").value, v2 = document.getElementById("combo_0").value; var amount3 = document.getElementById("txt_price3").value, amount = document.getElementById("txt_price").value; document.getElementById("txt_price3").value = (amount); document.getElementById("quantity").value = (v1); if (v2 == 70) { document.getElementById("state").value = ("AZ"); } <!-- when state is selected, these calculations are done --> if (v2 == 70) { if (v1 == 4) { document.getElementById("txt_price2").value = v1 * 20.95; document.getElementById("txt_product").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = document.getElementById("txt_product").value * 0.0795; document.getElementById("txt_tax").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = 12; document.getElementById("txt_shipping").value = document.getElementById("txt_price2").value; document.getElementById("txt_price2").value = v1 * 20.95 * 1.0795 + 12.00; } } }; document.getElementById("combo_0").onchange = dropChange; document.getElementById("combo_1").onchange = dropChange; }; </script> <script type="text/javascript"> <!-- var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["change"]}); var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {validateOn:["change"]}); var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1", {validateOn:["change"]}); var sprytextfield6 = new Spry.Widget.ValidationTextField("sprytextfield6", "none"); var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "zip_code", {validateOn:["change"]}); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "none"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none"); var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none"); var sprytextfield7 = new Spry.Widget.ValidationTextField("sprytextfield7", "none", {validateOn:["change"]}); var sprytextfield8 = new Spry.Widget.ValidationTextField("sprytextfield8", "currency", {validateOn:["change"]}); var sprytextfield10 = new Spry.Widget.ValidationTextField("sprytextfield10"); var sprytextfield9 = new Spry.Widget.ValidationTextField("sprytextfield9"); var sprytextfield11 = new Spry.Widget.ValidationTextField("sprytextfield11"); //--> </script> </body> </html> I need help with a javascript calculation. I am a noobie developer as you will probably see by my script but here are my goals: I already have a working bmi calculator for my website where visitor will enter height and current weight to calculate their current bmi. then I want to have a reverse bmi calculator to grab the same height and weight from said bmi calculator to give a calculation with a fillable goal bmi (example: 18-24 "healthy bmi") to read out a goal weight for them to achieve. I have already figured out the first part of the bmi calculation now i just need the second calculation to grab the height and weight from original bmi calculator without needing to be filled in again and compute result in a second table. I will post code that I have come up with so far for the whole page. Thank you in advance for your help! [CODE] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title> HCG Drops Fat Lose 1-2 pounds Per Day! </title> <style type="text/css"> #wrapall { width:1000px; align:center; margin-left: 7em; margin-right: 7em; } #navigationbar{ } #bmibar { width:973px; background-image:url(bmibar2.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:16em; margin:4px; } #Hcgborder { width:973px; background-image:url(index_15.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:17em; } #Hcgborder h3 { width:973px; background-image:url(index_12.jpg); background-repeat:no-repeat; background-position:left top; margin:0px; padding-left:4em; padding-top:8em; } p { background-image:url(index_13.jpg); background-repeat:repeat-y; background-position:left center; margin:0px; padding-left:4em; padding-right:4em; font:family"arial" } #bmiscale{ font-size:14px; padding-left:15px; } #Hcgborder2 { width:973px; background-image:url(index_19.jpg); background-repeat:no-repeat; background-position:left bottom; padding-bottom:0.5em; } #dhtmlgoodies_bmi_calculator{ width:180px; /* Width of entire calculator */ height:145px; /* Height of entire calculator */ font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; /* Fonts to use */ } #dhtmlgoodies_bmi_calculator .calculator_form{ /* Form */ width:180px; /* Width of form div */ float:left; /* Position the form at the left of the graph */ padding-left:5px; padding-right:5px; } #dhtmlgoodies_bmi_calculator input{ width:130px; } #dhtmlgoodies_bmi_calculator .calculator_form .textInput{ width:40px; /* Width of small text inputs */ text-align:right; /* Right align input text */ } .barContainer{ /* DIV for both the multicolor bar and users weight bar */ position:absolute; bottom:0px; border:0px solid #4ff; border-bottom:0px; text-align:center; vertical-align:middle; } .barContainer div{ /* colored div inside "barContainer */ border-bottom:1px solid #000; } .barContainer .labelSpan{ /* Label indicating users BMI */ background-color:#FFF; /* White BG */ border:1px solid #000; /* Black border */ padding:1px; /* "Air" inside the box */ font-size:0.9em; /* Font size */ } .clear{ /* Clearing div - you shouldn't do anything with this one */ clear:both; } </style> <script type="text/javascript"> var useCm = false; // Using centimetre for height, false = inch var useKg = false // Using kilos for weight, false = pounds var graphColors = ['#00baff','#02eb07','#ffb400','#ff0000']; var graphLabels = ['']; var labelsPerRow = 1; /* Help labels above graph */ var barHeight = 50; // Total height of bar var barWidth = 50; // Width of bars */ // Don't change anything below this point */ var calculatorObj; var calculatorGraphObj; var bmiArray = [0,18.5,25,30,60]; /* BMI VALUES */ var weightDiv = false; function calculateBMI() { var height = document.bmi_calculator.bmi_height.value; var weight = document.bmi_calculator.bmi_weight.value; height = height.replace(',','.'); weight = weight.replace(',','.'); if(!useKg)weight = weight / 2.2; if(!useCm)height = height * 2.54; if(isNaN(height))return; if(isNaN(weight))return; height = height / 100; var bmi = weight / (height*height); createWeightBar(bmi); } function createWeightBar(inputValue){ if(!weightDiv){ self.status = Math.random(); weightDiv = document.createElement('DIV'); weightDiv.style.width = barWidth + 'px'; weightDiv.className='barContainer'; weightDiv.style.left = Math.round((calculatorGraphObj.offsetWidth/2) + ((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; calculatorGraphObj.appendChild(weightDiv); var span = document.createElement('SPAN'); weightDiv.appendChild(span); var innerSpan = document.createElement('SPAN'); innerSpan.className='labelSpan'; span.appendChild(innerSpan); }else{ span = weightDiv.getElementsByTagName('SPAN')[0]; innerSpan = weightDiv.getElementsByTagName('SPAN')[1]; } var color = graphColors[graphColors.length-1]; for(var no = bmiArray.length-1;no>0;no--){ if(bmiArray[no]>inputValue)weightDiv.style.backgroundColor = graphColors[no-1]; } if(inputValue/1>1){ innerSpan.innerHTML = inputValue.toFixed(2); span.style.display='inline'; }else span.style.display='none'; var height = Math.min(Math.round(barHeight * (inputValue / bmiArray[bmiArray.length-1])),barHeight-10); span.style.lineHeight = Math.round(height) + 'px'; weightDiv.style.height = height + 'px'; } function validateField() { this.value = this.value.replace(/[^0-9,\.]/g,''); } function initBmiCalculator() { calculatorObj = document.getElementById('dhtmlgoodies_bmi_calculator'); calculatorGraphObj = document.getElementById('bmi_calculator_graph'); if(!useCm)document.getElementById('bmi_label_height').innerHTML = 'inches'; if(!useKg)document.getElementById('bmi_label_weight').innerHTML = 'pounds'; var heightInput = document.getElementById('bmi_height'); heightInput.onblur = validateField; var widthInput = document.getElementById('bmi_height'); widthInput.onblur = validateField; var labelDiv = document.createElement('DIV'); labelDiv.className = 'graphLabels'; calculatorGraphObj.appendChild(labelDiv); for(var no=graphLabels.length-1;no>=0;no--){ var colorDiv = document.createElement('DIV'); colorDiv.className='square'; colorDiv.style.backgroundColor = graphColors[no]; colorDiv.innerHTML = '<span></span>'; labelDiv.appendChild(colorDiv); var labelDivTxt = document.createElement('DIV'); labelDivTxt.innerHTML = graphLabels[no]; labelDiv.appendChild(labelDivTxt); labelDivTxt.className='label'; if((no+1)%labelsPerRow==0){ var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); } } var clearDiv = document.createElement('DIV'); clearDiv.className='clear'; labelDiv.appendChild(clearDiv); var graphDiv = document.createElement('DIV'); graphDiv.className='barContainer'; graphDiv.style.width = barWidth + 'px'; graphDiv.style.left = Math.round(((calculatorGraphObj.offsetWidth/2) /2) - (barWidth/2)) + 'px'; graphDiv.style.height = barHeight; calculatorGraphObj.appendChild(graphDiv); var totalHeight = 0; for(var no=bmiArray.length-1;no>0;no--){ var aDiv = document.createElement('DIV'); aDiv.style.backgroundColor = graphColors[no-1]; aDiv.innerHTML = '<span></span>'; var height = Math.round(barHeight * (bmiArray[no] - bmiArray[no-1]) / bmiArray[bmiArray.length-1]) - 1; aDiv.style.height = height + 'px'; graphDiv.appendChild(aDiv); } createWeightBar(1); } </script> <!-- function cal_bmi(lbs, ins){ h2 = ins * ins; bmi = lbs * h2/703 wtl = h2/703 * 24.9 f_bmi = Math.floor(bmi); diff = bmi - f_bmi; diff = diff * 10; diff = Math.round(diff); if (diff == 10){ f_bmi += 1; diff = 0; } bmi = f_bmi + "." + diff; return bmi; } function compute(){ var f = self.document.forms[0]; w = f.wt.value; v = f.htf.value; u = f.hti.value; // Format values for the calculation if (!chkw(u)){ var ii = 0; f.hti.value = 0; } else { var ii = parseInt(f.hti.value); } var fi = parseInt(f.htf.value * 12); var i = fi + ii; // Do validation of remaining fields if (!chkw(v)){ alert("Please enter your height."); f.htf.focus(); return; } if (!chkw(w)){ alert("Please enter your weight."); f.wt.focus(); return; } // Perform calculation f.bmi.value = cal_bmi(w, i); f.bmi.focus(); } function chkw(w){ if (isNaN(parseInt(w))){ return false; } else if (w < 0){ return false; } else{ return true; } } // --> </style> </head> <body> <div id="wrapall" align="center"> <img src="index_01_01.jpg" alt="Hcg drops fat banner"> <br/> <div id="navigationbar"> <a href="http://www.hcgdropsfat.com"><img src=hcghomeog.jpg border=0></a> <img src="hcgblogo.jpg" alt="Hcg blog"/> <img src="hcgfaqo.jpg" alt="Hcg faq"> <img src="hcgresourceso.jpg" alt="Hcg resources"> <img src="hcgtestimonialso.jpg" alt="Hcg testimonials"> <img src="hcgsupporto.jpg" alt="Hcg support"> <img src="hcgordero.jpg" alt="Hcg order"> <div id="bmibar"> <div style="position: absolute; top: 515px; left: 170px"; style="font-family: arial"; align="left";> How much is your weight in <br/>relation to your height <br/> <!--BMI CALCULATOR SCRIPT--> <div id="dhtmlgoodies_bmi_calculator"> <div class="calculator_form"> <form name="bmi_calculator"> <table> <tr> <td><label for="bmi_height">Height</label>:</td><td><input class="textInput" type="text" id="bmi_height" name="bmi_height"> <span id="bmi_label_height">cm</span></td> </tr> <tr> <td><label for="bmi_weight">Weight</label>:</td><td><input class="textInput" type="text" id="bmi_weight" name="bmi_weight"> <span id="bmi_label_weight">kg</span></td> </tr> <tr> <td colspan="2"><input type="button" onclick="calculateBMI()" value="Find BMI"></td> </tr> </table> </form> </div> <div class="calculator_graph" id="bmi_calculator_graph"> </div> </div> <script type="text/javascript"> initBmiCalculator(); </script> </div> <div style="position: absolute; top: 515px; left: 405px"; style="font-family: arial"; align="left";> What is your BMI category? <br/>This will help determine <br/>how much you need to lose <br/><br/><div id="bmiscale">Underweight = Under 18.5 <br/>Normal weight = 18.5 – 24.9 <br/>Overweight = 25 – 29.9 <br/>Obesity = 30 or more <br/><br/> </div></div> <div style="position: absolute; top: 515px; left: 640px"; style="font-family: arial"; align="left";> Calculate approximately how <br/>much weight you should lose<br/> to be at a healthy BMI <!--REVERSE BMI CALCULATOR--> <td width="81%" valign="top"> <br/><div align="center" class="page_header">Reverse BMI Calculator</div><br/> <div align="center" class="main_text"></div> <form action="" method="post" name="BMI_input" class="main_text" id="BMI_input"> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">Target BMI:<b> <input id="FormsEditField4" type="text" name="wt" value="24" size="3" maxlength="2" /> <br /> </b></font></div> <div style="text-align: center;"> <font face="Arial, Helvetica, sans-serif"> <input type="button" name="FormsButton1" value="Find Target Weight" id="FormsButton1" onclick="self.compute()" /> </font></div> <div style="text-align: center;"><font face="Arial, Helvetica, sans-serif">This is your Target Weight: <br /> <input id="FormsEditField5" type="text" name="bmi" value="" size="4" maxlength="5" /> </font></div> </div> </div> <div id="Hcgborder"> <h3></h3> <p align="left"><b> WHAT IS HCG? </b><BR/><BR/>In simple terms: its a hormone protein produced by pregnant women that when used as a homeopathic dietary supplement, will assist in a revolutionary cure to the traditional diet routine. <BR/><BR/><b>HCG is so unique from other diets in 3 major ways: </b> <br/><BR/><img src="muscletissue.jpg" alt="practice"style="float:right;" width="250px" height="250px"/> 1. USES HIGHEST FAT AS PRIMARY FUEL SOURCE FOR THE BODY - it begins to break down the abnormally high body fat as the primary fuel source (BURNS ALOT OF FAT!) <BR/>2. DOESNT EAT AT VITAL MUSCLE TISSUE - it will preserve and maintain lean body muscle (without HCG THE BODY WOULD DEPLETE VITAL MUSCLE TISSUE ON A LOW CALORIE DIET. Also if you burn muscle you also lose metabolism for each pound of muscle you lose you also lose 50 calories of metabolism) <BR/>3. WHILE MOST DIETS SLOW METABOLISM HCG ACTUALLY MAINTAINS IT EVEN AFTER THE DIET - because hcg maintains lean muscle and maintains metabolism, you keep your metabolism in check long after the diet program so you reset your bodys roaming weight. <BR/><BR/>THE HOMEOPATHIC DROPS YOU WILL FIND ON OUR SITE ARE ALL NATURAL <br/><BR/><b>HOW LONG HAS IT BEEN AROUND?</b> <BR/><BR/>HCG or (Human chorionic gonadotropin)<img src="nicefigure.jpg" alt="Hcg stored fat" style="float:right;" width="250px" height="250px"/> is a protein hormone </div><!--p1--> </div><!--Hcgborder--> <div id="Hcgborder2"> <p><b>hello</b></p> <p>Hello again</p> </div><!--Hcgborder2--> </div> </div><!--wrapall--> </body> </html> [CODE] Hi, I'm trying to make a calculator app; with a few differences. I have a text field with a numberpad below it, I got the numbers to show up in the text field, but am unsure as to how when I hit the enter button - it would store them in a variable?...I am also wondering as to how it would store current value and then allow me to input another value(maybe on the next page) and either subtract or add to it(the first value that is stored). I am also wondering how to get a decimal point in place(need it for currency). Any help would be greatly appreciated! Here is my code: Code: <html> <head> <script type = "text/javascript"> function decPoint(str){ if (str.indexOf('.') == -1) str += "."; var decNum = str.substring(str.indexOf('.')+1, str.length); if (decNum.length > 2) { alert("Invalid more than 2 digits after decimal") } else { alert("Valid no") } } var ent = document.write(document.getElementById("curamt").value); </script> </head> <body border = "1"; color = "blue";> <div id = "cur"> <p>amount is: <script>document.getElementById("amount").innerHTML = ent);</script> </p> <b>Please type in price of item:</b> <form name = "calculator"> <table border = "1"; color = "blue";> <tr> <td colspan = "3" width="75%" align = "center"> <input type = "tel" id = "curamt" name = "tinput" maxlength="4" size="6"> </td> </tr> <table> <tr> <td><input type = "button" name = "one" value = " 1 " onclick = "calculator.tinput.value += '1'"></td> <td><input type = "button" name = "two" value = " 2 " onclick = "calculator.tinput.value += '2'"></td> <td><input type = "button" name = "three" value = " 3 " onclick = "calculator.tinput.value += '3'"></td> </tr> <tr> <td><input type = "button" name = "four" value = " 4 " onclick = "calculator.tinput.value += '4'"></td> <td><input type = "button" name = "five" value = " 5 " onclick = "calculator.tinput.value += '5'"></td> <td><input type = "button" name = "six" value = " 6 " onclick = "calculator.tinput.value += '6'"></td> </tr> <tr> <td><input type = "button" name = "seven" value = " 7 " onclick = "calculator.tinput.value += '7'"></td> <td><input type = "button" name = "eight" value = " 8 " onclick = "calculator.tinput.value += '8'"></td> <td><input type = "button" name = "nine" value = " 9 " onclick = "calculator.tinput.value += '9'"></td> </tr> <tr> <td><input type = "reset" name = "clear" value = " c " onclick = "calculator.tinput.value = ''"></td> <td><input type = "button" name = "zero" value = " 0 " onclick = "calculator.tinput.value += '0'"></td> <td><input type = "submit" id = "amount" name = "enter" value = " e " onsubmit = "ent(); return false;"></td> </tr> </table> </table> </form> </div> </body> </html> Ok I am looking for a simple bmi calculator that calculates body mass index then in a seperate table calculates what a target weight should be based on the goal bmi. no need for making it look fancy, just functionality for now. thanks!
Hi, I am using the below code to calculate the age of a child from DOB. Criteria is as of 09/01/2010 (for the school year 2010-11). Even though the script seems to working fine in some cases the age calculations are wrong. Can some please tell what is wrong with the code. For ex: DOB 12/20/1999 the age should be 10 as if 09/01/2010. However the age is calculated as 11 years. Code: Function Row_Inserting(rs) If Not EW_DEBUG_ENABLED Then On Error Resume Next DIM ChildAge, fromDate fromDate=CDate("09/01/2010") ChildAge = DateDiff("d",rs("DOB"),fromDate) If ChildAge <= (Cint("1095")) Then CancelMessage="Your child is too young to attend our classes. Please register after your child has reached pre-K." Row_Inserting = False Else rs("Age")= DateDiff("YYYY",rs("DOB"),Date()) Row_Inserting = True End If End Function Any pointers .. Thanks Vinny |