JavaScript - Calculator Calculation Problem
I am a student trying to complete this assignment. Any assistance you can give me is greatly appreciated. My code is inserted below.
This is calculator program that I have gotten stuck on. Here is where I think I am at: The program is now taking the 1st number entered displaying it and storing it in the variable "memory". Operation (+,-,*,/) is added to the memory in function action1() but then when the second number is entered it replaces memory with the second number. How can I get the variable memory to the whole string of 1st number,action, 2nd number? Also once I do get that working correctly: Wouldn't eval(document.calculator.display.value= memory) in my HTML for the "=" give me the calculation. ( if I could figure out how to have memory store the 1st number and action1 and 2nd number all together) Or would eval(document.calculator.display.value) do it for me. //////////////////////////////////////////////////////////////////////////////////// <html> <head> <title> Calculator</title> </head> <script type = "text/javascript" src="calculator2.js"></script> <body> <center>Calculator<br> To use this calculator, CLICK a number, then an ACTION, then another number, then the EQUALS button. <br> Press "C" when ready to start over. <br> The "N" button makes your previous number a negative.<br></center> <form name="calculator"> <table border = "1" align ="center"> <tr> <td ><input type = "text" size = 26 name = "display" id = ""/></td> </tr> <tr ><br /> <!-- first row of calculator --> <td> <input type = "button" value = " 7 " id = "" onclick="newstring('7')"> <input type = "button" value = " 8 " id = "" onclick="newstring('8')"/> <input type = "button" value = " 9 " id = "" onclick="newstring('9')"> <input type = "button" value = " / " id = "" onclick="action1('/')"> </td> </tr> <tr ><br /> <!-- second row of calculator --> <td> <input type = "button" value = " 4 " id = "" onclick="newstring('4')"> <input type = "button" value = " 5 " id = "" onclick="newstring('5')"> <input type = "button" value = " 6 " id = "" onclick="newstring('6')"> <input type = "button" value = " * " id = "" onclick="action1('*')"> </td> </tr> <tr ><br /> <!-- third row of calculator --> <td> <input type = "button" value = " 1 " id = "" onclick="newstring('1')"> <input type = "button" value = " 2 " id = "" onclick="newstring('2')"> <input type = "button" value = " 3 " id = "" onclick="newstring('3')"> <input type = "button" value = " - " id = "" onclick="action1('-')"> </td> </tr> <tr ><br /> <!-- forth row of calculator --> <td> <input type = "button" value = " 0 " id = "" onclick="newstring('0')"> <input type = "button" value = " N " id = "" onclick="newstring('N')"> <input type = "button" value = " = " id = "" onclick="eval(document.calculator.display.value= memory)"> <input type = "button" value = " + " id = "" onclick="action1('+')"> </td> </tr> <tr ><br /> <!-- fifth row of calculator --> <td> <input type = "button" value = "   " id = ""> <input type = "button" value = "   " id = ""> <input type = "button" value = "   " id = ""> <input type = "button" value = " C " id = "" onclick="clearCalc()"> </td> </tr> </table> </body> </form> </html> /////////////////////////////////////////////////////////////////////////////////////// javascript memory = "0"; current = 0; operation =0; function newstring(digit) { current=document.calculator.display.value; if (digit >= 0 && digit <=9) { if(current==0) { current = digit; } else { current = current + digit; } } document.calculator.display.value=current; memory= current; } function action1(newaction) { operation = document.calculator.display.value; if (newaction == '+') { operation = newaction; } else if (newaction == '-') { operation = newaction; } else if (newaction == '*') { operation = newaction; } else if (newaction == '/') { operation = newaction; } memory= memory + operation; document.calculator.display.value=memory ; } function clearCalc() { document.calculator.display.value=null; num1= null; num2 = null; lastaction= null; action = null; } Similar TutorialsI've designed a snippet of javascript to receive numbers, add them together, and then display the total. What i'd like to do now is display the amount of numbers added together "count", and then average them all together. Problem is, the count just won't display, so i'm uncertain if I have a logic error in my code or just an html issue? I'd really appreciate the help! Code: <html> <head> <script type="text/javascript"> var count = 0; var total = 0; var number = 0; function AverageNumbers(form) { number = document.getElementById('num1').value; count++; total = parseInt(number) + parseInt(total); average = parseInt(number) + parseInt(count) if (number!=null && number!="") { document.getElementById('total').innerHTML = total; document.getElementById('count').innerHTML = count; } return count; return total; } </script> </head> <body> <form> <INPUT TYPE="number" NAME="inputbox" ID="num1"> <INPUT TYPE="button" NAME="button" Value="Click" onClick="AverageNumbers(this.form)"> </form> <div id="total"><div> <br> </br> <div id="count"><div> </body> </html> Hey I've been working on my Spanish Clubs' website over the summer and I need some help when making this converter. I want to make it so when someone chooses a different country, it will change the answeres and do the equation in the text boxes and also if they change the numbers manually they will also do the equation. I've tried it out and it's making me go mad. PLEASE HELP! Here is the javascript code I made: Code: function calculatecountry() { var country = calculate.countrys.options[calculate.countrys.selectedIndex].text; //===============================COUNTRIES==================================== if (countrys=="--Country--") { var usd1 = 0; var other1 = 0; } if (countrys=="Argentina") { var usd1 = 0.2553; var other1 = 1; } if (countrys=="Bolivia") { var usd1 = 0.14245; var other1 = 1; } if (countrys=="Chile") { var usd1 = 0.0018; var other1 = 1; } //================================EQUATIONS===================================== var c1 = calculate.other.value; var c2 = calculate.usd.value; var ans1 = c1 * other1; var ans2 = c2 * usd1; calculate.usd.value = ans1; calculate.other.value = ans2; } Here is the form code: Code: <html><head><title></title> <script type="text/javascript" src="js_money_calc.js"></script> </head><body> Converter <form name="calculate"> <select name="countrys" onChange="calculatecountry()"> <option selected>--Country--</option> <option>Argentina</option> <option>Bolivia</option> <option>Chile</option> </select><p> <input type="text" name="usd" onKeyUp="calculatecountry()" /> = <input type="text" name="other" onKeyUp="calculatecountry()" /></p> </form> </body></html> Thanks. I have this project i have to complete for class, that i cant figure out. this is what the project says: Prompt the user for the grades of 10 students with one prompt for each grade with the prompting text being: "Enter grade between 1 and 10 for student n:" where n varies from 1 to 10. If the grade input is not between 1 and 10, please prompt again for the grade. Once the user is done, it prints a report telling you the grade of each individual student and the average of the ten grades. The individual student grade should be in different lines with the text "Grade for student n is x". The average should also be in a different line with the text "Average grade is y". The average grade should not be rounded off. my problem is i cant figure out how to write each individual grade (from 1 through 10), and display it on the page. i have this code from a similar project, i tried to ammend it for this code but i always end up ruining it any tips on how to display each grade (1-10)? or how to verify that the user only enters grades between 1 and 10 Code: <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Class Average Program: Sentinel-controlled Repetition</title> <script type = "text/javascript"> <!-- var total; // sum of grades var gradeCounter; // number of grades entered var grade; // grade typed by user (as a string) var gradeValue; // grade value (converted to integer) var average; // average of all grades // Initialization phase total = 0; // clear total gradeCounter = 0; // prepare to loop // Processing phase // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); while ( gradeValue != -1 ) { // add gradeValue to total total = total + gradeValue; // add 1 to gradeCounter gradeCounter = gradeCounter + 1; // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); } // end while // Termination phase if ( gradeCounter != 0 ) { average = total / gradeCounter; // display average of exam grades document.writeln( "<h1>Class average is " + average + "</h1>" ); } // end if else document.writeln( "<p>No grades were entered</p>" ); // --> </script> </head> <body> <p>Click Refresh (or Reload) to run the script again</p> </body> </html> hi guys, im haveing a bit of a problem with this script - its a ratio calculator. can you guys see whats the problem? Heres the java script eg. when you write 86708 kills and 53240 death the K/D calc should show this: 1,62 = 86 (-86) 1,64 = 389 1,70 = 3582 but it doesent???? heres the code guys : <HTML> <HEAD> <script type="text/javascript"> function find_ratio() { var x = document.getElementById("x1").value; var y = document.getElementById("y1").value; var gcd=calc(x,y); var r1=x/gcd; var r2=y/gcd; var ratio = r1 / r2; document.getElementById("res").value = ratio.toFixed(2); var death1 = r1 / r2; death1 = Math.floor(ratio * 100) / 100; document.getElementById("death1").value = death1.toFixed(2); var kill1 = r1 / r2; kill1 = Math.ceil(ratio * 100) / 100; document.getElementById("kill1").value = kill1.toFixed(2); var kill3 = r1 / r2; kill3 = Math.ceil(ratio * 10) / 10; document.getElementById("kill3").value = kill3.toFixed(2); var deathcalc = (death1 - 0.00401) * r2; var death2 = deathcalc - r1; document.getElementById("death2").value = death2.toFixed(0); var killcalc1 = (kill1 - 0.00401) * r2; var kill2 = killcalc1 - r1; document.getElementById("kill2").value = kill2.toFixed(0); var killcalc2 = (kill3 - 0.00401) * r2; var kill4 = killcalc2 - r1; document.getElementById("kill4").value = kill4.toFixed(0); } function calc(n1,n2) { var num1,num2; if(n1 < n2){ num1=n1; num2=n2; } else{ num1=n2; num2=n1; } var remain=num2%num1; while(remain>0){ num2=num1; num1=remain; remain=num2%num1; } return num1; } function isInteger(s,iid) { var i; s = s.toString(); for (i = 0; i < s.length; i++) { var c; if(s.charAt(i)==".") { } else { c = s.charAt(i); } if (isNaN(c)) { alert("Given value is not a number"); document.getElementById(iid).value=""; return false; } } return true; } </script> <style type="text/css"> .style1 { width: 90px; } .style2 { height: 55px; } #x1 { text-align: center; } #y1 { text-align: center; } </style> </HEAD> <BODY> <table cellspacing=0 cellpadding=2 style="border:1px solid green; width: 250px; height: 217px;" align=center> <tr><td class="style1">Kills:</td><td style="text-align: center"><input type="text" id="x1" onkeyup="isInteger(this.value,this.id);"></td></tr> <tr><td class="style1">Death:</td><td style="text-align: center"><input type="text" id="y1" onkeyup="isInteger(this.value,this.id);"></td></tr> <tr><td colspan=2 align=center class="style2"><input type="button" value="Lad magien flyde" onclick="find_ratio()"></td></tr> <tr><td class="style1">Ratio:</td><td style="text-align: center"><input type="text" readonly id="res" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="res2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Deaths to:</td><td style="text-align: center"> <input type="text" readonly id="death1" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="death2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Kills to:</td><td style="text-align: center"> <input type="text" readonly id="kill1" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="kill2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Kills to:</td><td style="text-align: center"> <input type="text" readonly id="kill3" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="kill4" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr></table> </BODY> </HTML> Hi, I am new to Javascript and I am having a problem with this calculator I am building. The purpose is to see if you will be able to go to prom. In a form you input 4 pieces of info. (1)How much money the ticket costs. (2)How much money your tuxedo costs. (3)How much money the dinner costs. (4)How much money you have. I have the calculator set up, and it is supposed to add together the ticket cost, tuxedo cost, and dinner cost, and subtract it from how much money you have. I finished the code, and I am getting no error at the bottom of the screen, but the calculator doesn't work. So, I guess it is a logic error. Here is the code and a link to the page: http://themusiccove.com/Documents/prom2010.htm <html> <head> <title>Prom 2010</title> <script LANGUAGE="JAVASCRIPT"> function prom(myform) { var ticket=document.Calculator.ticket.value var ticket=parseInt(ticket,10) if (isNaN(ticket)) { alert("Enter a number for the Ticket Cost.") document.Calculator.ticket.value="" document.Calculator.ticket.focus() } else { var tuxedo=document.Calculator.tuxedo.value var tuxedo=parseInt(tuxedo,10) if (isNaN(tuxedo)) { alert("Enter a number for the Tuxedo Cost.") document.Calculator.tuxedo.value="" document.Calculator.tuxedo.focus() } else { var dinner=document.Calculator.dinner.value var dinner=parseInt(dinner,10) if (isNaN(dinner)) { alert("Enter a number for the Dinner Cost.") document.Calculator.dinner.value="" document.Calculator.dinner.focus() } else { var money=document.Calculator.money.value var money=parseInt(money,10) if (isNaN(money)) { alert("Enter a number for how much money you have.") document.Calculator.money.value="" document.Calculator.money.focus() Calculate=money-(ticket+tuxedo+dinner) document.Calculator.answer.value=Calculate } } } } } </script> </head> <body bgcolor="ccffcc"> <img src="http://www.shop-direct.net/images/prom5.jpg" align="left" width="125" length="100"> <img src="http://www.packerpress.com/wp-content/uploads/2009/05/5301-men-tuxedo-jacket-b.jpg" align="right" width="125" length="100"> <h2><center>Prom Calculator</center><h2> <h4><center>Enter the data in the textboxes to see if you have enough money to go to prom.</center></h4> <Center><FORM Name="Calculator"> <table border="0"> <tr> <td><p align=right>Ticket Cost: </td> <td><Input Type="text" Name="ticket" value=" "></td> </tr> <tr> <td><p align=right>Tuxedo Cost: </td> <td><Input Type="text" Name="tuxedo" value=" "></td> </tr> <tr> <td><p align=right>Dinner Cost: </td> <td><Input Type="text" Name="dinner" value=" "></td> </tr> <tr> <td><p align=right>Your Money: </td> <td><Input Type="text" Name="money" value=" "></td> </tr> <tr> <td><p align=right>Profit/Loss: </td> <td><Input Type="text" Name="answer" value=" "></td> </tr> <tr align="center"> <td colspan=2><Input Type="Button" Value="Calculate" Onclick="prom(Calculator)"></tr> <tr align="center"><td colspan=2><Input Type="Reset"></td></tr> </table></center> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers //--> </SCRIPT> <CENTER><HR Width="75%"></CENTER> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers var tNow = new Date() var tlocDate = tNow.toLocaleString() var tDate = tlocDate.substring(0,23) document.write("<H2><CENTER>Welcome, today is "+tDate+"</CENTER></H2>") //--> </SCRIPT> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers document.write("<H4><CENTER>This document was last modified "+document.lastModified+"</CENTER></H4>") //--> </SCRIPT> </body> </html> 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> 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] 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> 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. 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!
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. I'm making a form for my rural neighbors' electricity calculations. My main problem is getting the Previous and Current reading to subtract each other and post in the "kwh Used" column. My plan is to continue doing the calculations after I find that value. Here is the code thus far: Code: <head> <title>Untitled Document</title> <script language="javascript"> function calc() { preR= Number(document.Bill_cal.PrRe.value); curR= Number(document.Bill_cal.CuRe.value); diff=preR-curR; document.getElementByID("kwhu").innerHTML=diff; } </script> </head> <body><center> <form name="Bill_cal" method="post" /> <input type="checkbox" value="Residential Account" name="Residential_Account" />Residential Account <input type="checkbox" value="GSS/Business Account" name="GSS_Business Account" />GSS/Business Account <br /> <br/> <input type="checkbox" value="Winter_Rate" name="Winter_Rate" onchange="" />Winter Rate <input type="checkbox" value="Summer_Rate" name="Summer_Rate" onchange="" />Summer Rate <br /> <br/> <input type="checkbox" value="Butler" name="Butler" onchange="" />Butler <input type="checkbox" value="Chautauqua" name="Chautauqua" onchange="" />Chautauqua <input type="checkbox" value="Cowley" name="Cowley" onchange="" />Cowley <input type="checkbox" value="Elk" name="Elk" onchange="" />Elk <input type="checkbox" value="Montgomery" name="Montgomery" onchange="" />Montgomery <br/> <br/> <input type="checkbox" value="Security Light" name="Security" /> Security Light (Check if Yes) <br/> <br/> </center> <center> <table width="600" border="1"><center> <tr> <th width="254" scope="col"> </th> <th width="168" scope="col"> </th> <th width="156" scope="col"> </th> </tr> <tr> <th scope="row">Previous Reading</th> <td><input type="text" name="PrRe" value="" /></td> <td> </td> </tr> <tr> <th scope="row">Current Reading</th> <td><input type="text" name="CuRe" value="" /></td> <td> </td> </tr> <tr> <th scope="row">kwh Used</th> <td> <p id="kwhu"></p> </td> <td> </td> </tr> <tr> <th scope="row">kwh Charge</th> <td></td> <td> </td> </tr> <tr> <th scope="row">Subtotal</th> <td>$</td> <td> </td> </tr> <tr> <th scope="row">Tax</th> <td>$</td> <td> </td> </tr> <tr> <th scope="row">PCA Charge from card:</th> <td><input type="text" name="PCA" value="" /></td> <td> </td> </tr> <tr> <th scope="row">Any Additional amount from card:</th> <td><input type="text" name="PCA" value="" /></td> <td> </td> </tr> <tr> <th scope="row">Total:</th> <td>$</td> <td> </td> </tr> </center></table> <input type="submit" value="Click here" onclick="calc()"> </form> </center></body> </html> One other issue I will probably run into and while I am on here posting. Can I preform a if statement within a if statement? Example: Code: if (Business is checked) { if (Winter is Checked) { } else if (Summer is Checked) { } } Hello, javascript seems to return the calculate the follwoing: (1 / 0.88) * 4.4 = 5.000000000000001 Excel evaluates the same sum to be 5 even to 20 decimal points. My calculator does the same. Having the 1 on the end throws off some of my calculations. Why is javascript evaluating like this?? Many thanks Hi. I am new to javascript programming so please go easy on me. I am creating a site for a flooring store and need to include a price calculator/estimator. What I need to do is allow the visitor to input the room size (length x width) and choose a flooring material from a pulldown list, and receive a price. The pulldown list would have flooring materials such as carpet, tile, wood, etc and each of these would have a fixed dollar amount associated with them (which would be hidden). So basically it is just a script that would multiply 3 numbers, with two of the numbers being input by the visitor, and th tird being selected from the pulldown. Can someone please educate me on how to do this? All, Below find my JS which is supposed to do the following: Take user supplied numerical values from 7 fields, perform the calculation function that's in the code and place it into the Total box / field. Needless to say ...or I wouldn't be here...it doesn't work. I thought maybe the problem was in the function, but I'm not sure Thanks to all who can help! NewbieScott ================================ <html> <head> <title>Test Prototype</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <style type="text/css"> * { margin:0; padding:0; } body { background:#fff; } p { margin:2em; } </style> <script type="text/javascript"> function calc(D1,D2,D3,D4,D5,D6,D7){ return (((D1*2.036+D3)/(273+D5))-((D2*2.036+D4)/(273+D6)))*238*(3050/D7); var D1=parseInt(D1.value); var D2=parseInt(D2.value); var D3=parseInt(D3.value); var D4=parseInt(D4.value); var D5=parseInt(D5.value); var D6=parseInt(D6.value); var D7=parseInt(D7.value); if (isNaN(D1)) {D1=0;} if (isNaN(D2)) {D2=0;} if (isNaN(D3)) {D3=0;} if (isNaN(D4)) {D4=0;} if (isNaN(D5)) {D5=0;} if (isNaN(D6)) {D6=0;} if (isNaN(D7)) {D7=0;} document.getElementById('total').value = D1+D2+D3+D4+D5+D6+D7; } window.onload=function() { var D1=document.getElementById('D1'); var D2=document.getElementById('D2'); var D3=document.getElementById('D3'); var D4=document.getElementById('D4'); var D5=document.getElementById('D5'); var D6=document.getElementById('D6'); var D7=document.getElementById('D7'); D1.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D2.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D3.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D4.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D5.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D6.onkeyup=function() {calc(D1,D2,D3,D4,D4,D6,D7); D7.onkeyup=function() {calc(D1,D2,D3,D4,D5,D6,D7); } </script> </head> <body> <form action="#"> <p><label> Number 1: <input id="D1"></label> <p><label> Number 2: <input id="D2"></label> <p><label> Number 3: <input id="D3"></label> <p><label> Number 4: <input id="D4"></label> <p><label> Number 5: <input id="D5"></label> <p><label> Number 6: <input id="D6"></label> <p><label> Number 7: <input id="D7"></label> <p>Total = <input id="total"></p> </p> </body> </html> Hi, I'm trying to get my head around JS, but not too successfully yet. My objective is probably simple (but not to me ): to have a form where visitors enter 12 separate digits (ideally in minutes & hours, but am happy to use decimals), and the average of these (to two decimal points) is returned as document.write is it? - along with other text, to make a complete & coherent sentence, including the average of the 12 numbers. Does anyone have any code convenient that could do this? Thanks, LJ 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 What code must I use if I want to create an order form on my website where patrons can order and/or request a product and/or services from the price list, the order form should calculate the total amount of the products/services requested, the VAT of 15% and add that to the order amount, Please help?
Can someone PLEASE show me what I am doing wrong with my code here? Basically, I have a registration form. In this registration form, I have 4 people register. It depends on each person birthyear to determine the amount of fees for each person. The fees a Registration Fee, Hotel Fee, Meal Fee, Discount Also, the trick is only first and second persons get Hotel Fee and Discount Fee. Third and Fourth person only pay Registration Fee and Meal Fee. So when user select birthyear from a dropdown menu for each person, the fees will be automatically filled in the input fields for each person and then do a total calculation. Each person will have a total of fees and there is another total field to automatically total up all 4 total fields from those 4 people. So here is my code so far Javascript Code: <script type="text/javascript"> function doUpdate(year, num) { if (isNaN(year)) return; var regfee = '0'; var meal = '0'; var hotel = '0'; //REGISTRATION Price if (year >= 2000) { regfee = '0'; } else if (year < 2000 && year > 1995 ) { regfee = '20'; } else { regfee = '30'; } //MEAL Price if (year < 2001) { meal = '80'; } else if (year >= 2001 && year <= 2009) { meal = '60'; } else { meal = '0'; } // HOTEL Price if(document.getElementById('year1').value!='') { hotel='199'; } else if (document.getElementById('year2').value!='') { hotel='199'; } //DISCOUNT Price if (document.getElementById('vip'+num).checked==true) { if (year > 1993) { discount = '0'; } else if (year == 1993) { discount = '0'; } else { discount = '-20'; } } else { if (year > 1993) { discount = '0'; } else if (year == 1993) { discount = '0'; } else { discount = '-10'; } } document.getElementById('regfee' + num).value = regfee; document.getElementById('meal' + num).value = meal; if(document.getElementById('year1').value!=''){ document.getElementById('hotel1').value = hotel; document.getElementById('discount1').value = discount; //Write to total field for second person document.getElementById('total1').value = parseInt(regfee)+parseInt(meal)+parseInt(hotel)+parseInt(discount); } if(document.getElementById('year2').value!=''){ document.getElementById('hotel2').value = hotel; document.getElementById('discount2').value = discount; //Write to total field for second person document.getElementById('total2').value = parseInt(regfee)+parseInt(meal)+parseInt(hotel)+parseInt(discount); } if(document.getElementById('year3').value!='' && document.getElementById('year4').value!=''){ document.getElementById('hotel3').value == '0'; document.getElementById('discount3').value == '0'; document.getElementById('hotel4').value == '0'; document.getElementById('discount4').value == '0'; // Write to total fields for third and fourth person document.getElementById('total3').value = parseInt(regfee)+parseInt(meal); document.getElementById('total4').value = parseInt(regfee)+parseInt(meal); } // Write to subtotal field by sum up all 4 total fields document.getElementById('subtotal1').value = parseInt(document.getElementById('total1').value) + parseInt(document.getElementById('total2').value) + parseInt(document.getElementById('total3').value) + parseInt(document.getElementById('total4').value); } </script> and here is my form Code: <form action="form.html" method="post" class="js_submit" name="form1" id="form1"> <table> <tr> <td>VIP</td> <td>Birthyear</td> <td>Registration Fee</td> <td>Hotel Fee</td> <td>Meal Fee</td> <td>Discount</td> <td>Total</td> </tr> <!-----------First Persion -------------------> <tr> <td><input type="checkbox" name="vip1" id="vip1" value="Y" class="inpt_c" /></td> <td><select name="year1" id="year1" onchange='doUpdate(this.value * 1,1);'> <option selected="selected"></option> <option value="2011">2011<option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> </select></td> <td><input type="text" id="regfee1" name="regfee1" class="inpt_a" value=""/></td> <td><input type="text" value="" id="hotel1" name="hotel1" class="inpt_a" /></td> <td><input type="text" value="" id="meal1" name="meal1" class="inpt_a" /></td> <td><input type="text" value="" id="discount1" name="discount1" class="inpt_a"/></td> <td><input type="text" value="" id="total1" name="total1" class="inpt_a" /></td> </tr> <!------------Second Person -----------------> <tr> <td><input type="checkbox" name="vip2" id="vip2" value="Y" class="inpt_c" /></td> <td><select name="year2" id="year2" onchange='doUpdate(this.value * 1,2);'> <option selected="selected"></option> <option value="2011">2011<option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> </select></td> <td><input type="text" id="regfee2" name="regfee2" class="inpt_a" value=""/></td> <td><input type="text" value="" id="hotel2" name="hotel2" class="inpt_a" /></td> <td><input type="text" value="" id="meal2" name="meal2" class="inpt_a" /></td> <td><input type="text" value="" id="discount2" name="discount2" class="inpt_a"/></td> <td><input type="text" value="" id="total2" name="total2" class="inpt_a" /></td> </tr> <!-----------Third Person -------------------> <tr> <td><input type="checkbox" name="vip3" id="vip3" value="Y" class="inpt_c" /></td> <td><select name="year3" id="year3" onchange='doUpdate(this.value * 1,3);'> <option selected="selected"></option> <option value="2011">2011<option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> </select></td> <td><input type="text" id="regfee3" name="regfee3" class="inpt_a" value=""/></td> <td><input type="text" value="" id="hotel3" name="hotel3" class="inpt_a" /></td> <td><input type="text" value="" id="meal3" name="meal3" class="inpt_a" /></td> <td><input type="text" value="" id="discount3" name="discount3" class="inpt_a"/></td> <td><input type="text" value="" id="total3" name="total3" class="inpt_a" /></td> </tr> <!----------Fourth Person --------------------> <tr> <td><input type="checkbox" name="vip4" id="vip4" value="Y" class="inpt_c" /></td> <td><select name="year1" id="year1" onchange='doUpdate(this.value * 1,4);'> <option selected="selected"></option> <option value="2011">2011<option> <option value="2010">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> </select></td> <td><input type="text" id="regfee4" name="regfee4" class="inpt_a" value=""/></td> <td><input type="text" value="" id="hotel4" name="hotel4" class="inpt_a" /></td> <td><input type="text" value="" id="meal4" name="meal4" class="inpt_a" /></td> <td><input type="text" value="" id="discount4" name="discount4" class="inpt_a"/></td> <td><input type="text" value="" id="total4" name="total4" class="inpt_a" /></td> </tr> <!------------Subtotal of all 4 totals above ------------> <tr> <td colspan="6"> <input name="subtotal1" type="text" id="subtotal1" class="inpt_a" value="" readonly="readonly" /></td> </tr> </form> Here is my form URL: http://daihoibaptit.org/form.html Thanks for your help |