JavaScript - Very New To Js, Need Help With An Averages Calculator
I have my first ever scholastic JS assignment and so far it's felt nearly impossible to get a grip on how to do it. I've gone through the W3c tutorials entirely 3 times now and still, nothing is clicking mentally. Generally I do better if I can reverse engineer already written code but I can't find anything similar enough to this on the net to figure it out.
The assignment is to create a grade averages calculator as seen in this pictu Along with this starter code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Assignments score calculator</title> <style type="text/css"> <!-- .score { width: 30px; } --> </style> </head> <body> <h1>Assignments score calculator</h1> <form id="calculator" name="calculator" method="post" action=""> <p>Enter your Name: <label for="firstname"></label> <br /> <input type="text" name="firstname" id="firstname" /> <p> <label for="A1">Assignment #1 sco </label> <input name="A1" type="text" class="score" id="A1" maxlength="3" /><br /> <label for="A2">Assignment #2 sco </label> <input name="A2" type="text" class="score" id="A2" maxlength="3" /><br /> <label for="A3">Assignment #3 sco </label> <input name="A3" type="text" class="score" id="A3" maxlength="3" /> <p> <label for="button"></label> <input type="submit" name="Submit" id="Submit" value="Submit" xx="doCalculation(this.form.firstname.value,this.form.A1.value,this.form.A2.value,this.form.A3.value)" /> </form> </body> </html> I understand what I need to do, just not the syntax to do it. Any help would be appreciated. Sorry for newbiness. Similar TutorialsI am having some issues with my code... The code is supposed to ask for an average of the values in the numeric property (Cost), which works, but it repeating itself twice. Also, I need to calculate and display the number of elements of (Cost), whose numeric property values is greater than the average. ANY help is highly appreciated ... Thanks! var expense = new Array(); var loop; var property; var numExpense; var LOOP_START = 1; var average = 0; var numberAverage = 0; numExpense=parseInt(prompt("How many expenses?")); for (loop = 0; loop < numExpense; loop++) { expense[loop] = new Object(); } expense[0].Name = prompt("Expense Name?"); expense[0].Cost = parseFloat(prompt("Expense Cost ?")); expense[0].Type = prompt("Expense Type?"); expense[0].Location = prompt("Expense Location?"); for (loop = LOOP_START; loop < numExpense; loop++) { expense[loop].Name = prompt("Expense Name?"); expense[loop].Cost = prompt("Expense Cost?"); expense[loop].Type = prompt("Expense Type?"); expense[loop].Location = prompt("Expense Location?"); } document.write("<br /> <h2> Expenses </h2>"); for(loop = 0; loop < numExpense; loop ++) { for(property in expense[loop]) { document.write("<br />Expense # " + (loop + 1) + " " + property + " : " + expense[loop][property]); } document.write("<br />"); } for(loop = 0; loop < numExpense; loop ++) { for(property in expense[loop]) { average=expense[loop].Cost/numExpense } document.write("<br />Average Cost: $ " + average); } for(loop = 0; loop < numExpense; loop ++) { for(property in expense[loop]) { parseInt(numberAverage) = numExpense > average } document.write("<br />Number of expenses more than Average: $ " + numberAverage); } Hey Coding Forum, Hey as you probably know iam new here as i probably haven't even posted this in the correct place but i have a real problem with my JavaScript and i can't get it to do what i would like. I have to write a code to show a new array to represent the third row of a table (var myarray value of which are "60","80","187","180","114" , and creating an array of the required length. Which i have done. (i Think ) I now need to write the remainder of the JavaScript needed to calculate the average height of the objects and write it out in the browser window. It need to write average height 17.2 cm. I have included my script below and but i am not understanding how to work out the average, i believe i need to add another 'for loop' but i can't get it to work correctly. (i might be being completely stupid) If anyone would be able to help it would be GREATLY appreciated. Thanks for all help. <HTML> <HEAD> <TITLE> Test Experiment </TITLE> <SCRIPT LANGUAGE = "JavaScript"> var height = [15,16,17,18,19]; var number = [4,5,11,10,6]; var myarray = new Array(5) var myarray = ["60","80","187","180","114"] ; var values = [60, 80, 187, 180, 114]; var total = 0; for ( var i = 0; i < values.length; ++i ) { total += values[i]; } var myarray = total + values.length; document.write('average height of the object is ' +myarray + '<br>'); </SCRIPT> </HEAD> <BODY> </BODY> </HTML> Hi , this is my bmi calculator script <HEAD> <script type="text/javascript"> <!-- Begin script of spillo3000 function calculateBMI() { var weight = eval(document.form.weight.value) var height = eval(document.form.height.value) var height2 = height / 100 var BMI = weight / (height2 * height2) if(weight == "" || isNaN(weight) || height2 == "" || isNaN(height2)) { alert("inserisci un valore"); return; } else { document.form.BodyMassIndex.value=custRound(BMI,1); if(BMI < 18.5) { document.getElementById('feedback').innerHTML = 'Underweight '; }else if(BMI >=18.5 && BMI < 29.9) { document.getElementById('feedback').innerHTML = 'Normal '; }else if(BMI > 29.9) { document.getElementById('feedback').innerHTML = 'Overweight '; } } } function custRound(x,places) { return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places) } function resetAll(){ document.getElementById('feedback').innerHTML=""; return true; } // End --> </script> </HEAD> <!-- --> <BODY> <div align="left"> <form name="form" id="form"> <input type="Text" name="weight" size="4"> Peso (Kg)<br> <input type="Text" name="height" size="4"> Altezza (Cm)<br> <input type="Text" name="BodyMassIndex" id="BodyMassIndex" size="4"> BMI<br> <input type="Text" name="feedback" id="feedback" style="padding:10px 0 20px 0; border:none; font-weight:600; color:#555555; font-family:verdana;" ><br> <input type="button" style="font-size: 8pt" value="Calcola" onClick="calculateBMI()" name="button"> <input type="reset" style="font-size: 8pt" value="Reset" onclick="resetAll()" name="button"> </form> </div> <!-- Script Size: I would want to show writing that it says if is in overweight, norms or I underweigh, but the script does not work. could someone help me? please I'm using the following code to calculate an age from the given date of birth however it works for some DOB's, gives wrong answers for some and undefined for others, can someone help me? Code: <div style="font-size:13px; font-family:Verdana;"> <script> <!-- /*Darren McGrady */ var current= new Date() var day = current.getDate() var month = current.getMonth() + 1 var year = current.getFullYear() var a = 29 var b = 12 var c = 1980 var age if (month < b) age = (year-c)-1 if ((month == b) && (day < a)) age = (year-c)-1 else age = year-c document.write(age); //--> </script> </div> Below is the code for a calculator using script. can one help me to explain me the colored line?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> </body> <script language="javascript" type="text/javascript"> function multiply() { a=Number Quote: Quote: (document.calculator.number1.value) ; b=Number(document.calculator.number2.value); c=a*b; document.calculator.total.value=c; } function addition(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a+b; document.calculator.total.value=c; } function subtraction(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a-b; document.calculator.total.value=c; } function division(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a/b; document.calculator.total.value=c; } function modulus(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a%b; document.calculator.total.value=c; } </script> </head> <body> <form name="calculator"> Number 1: <input type="text" name="number1"> Number 2: <input type="text" name="number2"> Get Result: <input type="text" name="total"> <input type="button" value="ADD" onclick="javascript:addition();"> <input type="button" value="SUB" onclick="javascript:subtraction();"> <input type="button" value="MUL" onclick="javascript:multiply();"> <input type="button" value="DIV" onclick="javascript:division();"> <input type="button" value="MOD" onclick="javascript:modulus();"> </form> </body> </html> How could i make a calculator that changes three values when a vertex on an image moves. Example : When a point moves on the triangle it changes the cost quality and time. I have this start and need the meat for the concept to work.<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <p><img src="Assets/Project-triangle.svg.png" width="500" height="492" alt=""/>-------------------------------------------<img src="Assets/triangle.gif" width="224" height="210" alt=""/></p> <p> <label for="textfield">Cost :</label> <input type="text" name="textfield" id="textfield"> <label for="textfield2"> Time :</label> <input type="text" name="textfield2" id="textfield2"> <label for="textfield3">Quality :</label> <input type="text" name="textfield3" id="textfield3"> </p> <p> </p> </body> </html> Help would be greatly appreciated! Hi all. I'm having a bit of a problem returning a different value each time a different button is pressed for calculator. What am I doing wrong? Code: <script> function calc(btname){ for(var x=0;x<=11;x++){ if(x==0){ btname="zero"; }else if(x==1){ btname="one"; }else if(x==2){ btname="two"; }else if(x==3){ btname="three"; }else if(x==4){ btname="four"; }else if(x==5){ btname="five"; }else if(x==6){ btname="six"; }else if(x==7){ btname="seven"; }else if(x==8){ btname="eight"; }else if(x==9){ btname="nine"; }else if(x==10){ btname="multiply"; }else if(x==11){ btname="divide"; } if('document.forms.test.'+btname+'.onClick'){ alert(btname); } } } function scalc(){ var sign=""; var btname=""; document.write('<form name="test">'); for(var x=0;x<=11;x++){ if(x==0){ btname="zero"; }else if(x==1){ btname="one"; }else if(x==2){ btname="two"; }else if(x==3){ btname="three"; }else if(x==4){ btname="four"; }else if(x==5){ btname="five"; }else if(x==6){ btname="six"; }else if(x==7){ btname="seven"; }else if(x==8){ btname="eight"; }else if(x==9){ btname="nine"; }else if(x==10){ btname="multiply"; sign = "*"; }else if(x==11){ btname="divide"; sign = "/"; } if(x<10){ document.write('<input type="button" size="30" name="'+btname+'" value="'+x+'" onClick="calc(this);"> '); }else if(x>9 && x<12){ document.write('<input type="button" size="30" name="'+btname+'" value="'+sign+'" onClick="calc(this);"> '); } if(x==2 || x == 5 || x == 8){ document.write('<br>'); } } document.write('</form>'); } scalc(); </script> ANY help is GREATLY appreciated! I've got this code below, it seems ok, but sometimes, the multiplication does not work..i don't know why... pls help me..thanks btw, this is my 1st javascript "application", so, im really new into this thanks in advance for any help Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>My First JavaScript Application</title> <style type="text/css"> td { text-align:center } table { background:#660033 } body { background-color:#666; text-wrap:supress; } h1 { color:#FFFFFF; } .ex { background-color:#99F; color:#660000; font:Verdana, Geneva, sans-serif; font-size:20px; text-align:right; } .ec { background-color:#CCC; color:#660033; font:Arial, Helvetica, sans-serif; font-size:18px; } </style> <script type="text/javascript"> var num1 = 0; var ope = 0; var num2 = 0; var ek = 0 function addOnScr1() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+1; document.getElementById("nums").value = txt; } function addOnScr2() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+2; document.getElementById("nums").value = txt; } function addOnScr3() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+3; document.getElementById("nums").value = txt; } function addOnScr4() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+4; document.getElementById("nums").value = txt; } function addOnScr5() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+5; document.getElementById("nums").value = txt; } function addOnScr6() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+6; document.getElementById("nums").value = txt; } function addOnScr7() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+7; document.getElementById("nums").value = txt; } function addOnScr8() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+8; document.getElementById("nums").value = txt; } function addOnScr9() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+9; document.getElementById("nums").value = txt; } function addOnScr0() { document.getElementById("neg").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+0; document.getElementById("nums").value = txt; } function addOnScrp() { document.getElementById("neg").disabled=true; document.getElementById("point").disabled=true; if((ek!=0)) { document.getElementById("nums").value = ""; ek = 0; } var txt = document.getElementById("nums").value; txt = txt+"."; document.getElementById("nums").value = txt; } function addOnScrn() { var txt = document.getElementById("nums").value; txt = txt+"-"; document.getElementById("nums").value = txt; } function add() { document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek=1; if(num1==0) { num1 = parseFloat(document.getElementById("nums").value); } else { ent(); } ope = 1; } function diff() { document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek=1; if(num1==0) { num1 = parseFloat(document.getElementById("nums").value); } else { ent(); } ope = 2; } function prod() { document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek=1; if(num1==0) { num1 = parseFloat(document.getElementById("nums").value); } else { ent(); } ope = 3; } function quo() { document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek=1; if(num1==0) { num1 = parseFloat(document.getElementById("nums").value); } else { ent(); } ope = 4; } function clr() { num1 = 0; num2 = 0; ope = 0; document.getElementById("nums").value = ""; document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek = 0; } function ent() { ek = 1; var ans; num2 = parseFloat(document.getElementById("nums").value); switch(ope) { case 1: ans = num1 + num2; document.getElementById("nums").value = ans; num1 = ans; break; case 2: ans = num1 - num2; document.getElementById("nums").value = ans; num1 = ans; break; case 3: ans = num1 * num2; document.getElementById("nums").value = ans; num1 = ans; break; case 4: ans = num1 / num2; document.getElementById("nums").value = ans; num1 = ans; break; default: document.getElementById("nums").value = "???"; } } function enterz() { document.getElementById("neg").disabled=false; document.getElementById("point").disabled=false; ek = 1; var ans; num2 = parseFloat(document.getElementById("nums").value); switch(ope) { case 1: ans = num1 + num2; document.getElementById("nums").value = ans; num1 = 0; break; case 2: ans = num1 - num2; document.getElementById("nums").value = ans; num1 = 0; break; case 3: ans = num1 * num2; document.getElementById("nums").value = ans; num1 = 0; break; case 4: ans = num1 / num2; document.getElementById("nums").value = ans; num1 = 0; break; default: document.getElementById("nums").value = "???"; } } </script> </head> <body><center> <form><h1> Calculator</h1> <table border="0"> <tr><th colspan="4"><input type="text" class = "ex" id = "nums" name = "nums" /></th></tr> <tr><td><button type="button" class = "ec" onclick="addOnScr1()">1</button></td> <td><button type="button" class = "ec" onclick="addOnScr2()">2</button></td> <td><button type="button" class = "ec" onclick="addOnScr3()">3</button></td> <td><button type="button" class = "ec" onclick="add()">+</button></td> </tr> <tr><td><button type="button" class = "ec" onclick="addOnScr4()">4</button></td> <td><button type="button" class = "ec" onclick="addOnScr5()">5</button></td> <td><button type="button" class = "ec" onclick="addOnScr6()">6</button></td> <td><button type="button" class = "ec" onclick="diff()">--</button></td></tr> <tr><td><button type="button" class = "ec" onclick="addOnScr7()">7</button></td> <td><button type="button" class = "ec" onclick="addOnScr8()">8</button></td> <td><button type="button" class = "ec" onclick="addOnScr9()">9</button></td> <td><button type="button" class = "ec" onclick="prod()">*</button></td></tr> <tr><td><button type="button" class = "ec" id="neg" onclick="addOnScrn()">-</button></td> <td><button type="button" class = "ec" onclick="addOnScr0()">0</button></td> <td><button type="button" class = "ec" id="point" onclick="addOnScrp()">.</button></td> <td><button type="button" class = "ec" onclick="quo()">/</button></td></tr> <tr><td></td> <td><button type="button" class = "ec" onclick="enterz()">=</button></td> <td><button type="button" class = "ec" onclick="clr()">C</button></td><td> </td></tr> </form> </body> </html> I'm not sure what the code is to add this to javascript. I don't know if anyone can help me with this? Each numeric button should change the input box up at the top to whatever. When one of the operator buttons (+,-,*,/) is pressed, the value in the input box at the top should change to 0. Before an operator button is pressed, the value should be stored in a variable to keep track of the left-hand side of the equation. After it is pressed, the value should be stored in the right hand side variable. Thanks Hi all master and expert coders I am working on a calculator which using the instructor's codes from the school. The problem that I having right now is the operator. I have successfully complete only the addition, but could not manage on subtraction and the rest operator. I hope experienced codes would help me out on this. Below is my codes. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <script type="text/javascript"> function calculate() { var value1 = parseInt(validate(document.getElementById("value1").value)); var value2 = parseInt(validate(document.getElementById("value2").value)); radioButtonCheck(); checkboxCheck(); dropDownListCheck(); document.getElementById("result").value = addition(value1, value2); document.getElementById("result").value = subtraction(value1, value2); document.getElementById("result").value = multiplication(value1, value2); document.getElementById("result").value = division(value1, value2); } function validate(value) { if (value == null || value == "") { alert("Required Field"); return 0; } else if (isNaN(value)) { alert("Must be a number"); return 0; } else return value; } function addition(value1, value2){ return value1 + value2; } // trying to use the same addition return statement but fail. function radioButtonCheck() { if ((document.getElementById("radio1").checked == false) && (document.getElemtById("radio2").checked == false)) { alert("Please select a radio button"); valid = false; } } function checkboxCheck() { if ((document.getElementById("cbox1").checked == false) && (document.getElementById("cbox2").checked == false)) { alert("Please select a checkbox"); valid = false; } } function dropDownListCheck() { if ((document.getElementById("ddlOperator").selectedIndex == 0)) { alert("Please select a operator"); valid = false; } } </script> <title>Calculator By Alsus</title> </head> <body> <h2>Calculator</h2> <table border = "1"> <tr> <td>Value 1:</td> <td><input type="text" id="value1" name="value1" /></td> </tr> <tr> <td>Value 2:</td> <td><input type="text" id="value2" name="value2" /></td> </tr> <tr> <td>Operator:</td> <td><input type="text" id="Operator" name="Operator" /></td> </tr> <tr> <td><input type="radio" id="radio1" name="radio1" value="radio1" />Radio1<br /></td> <td><input type="radio" id="radio2" name="radio2" value="radio2" />Radio2<br /></td> </tr> <tr> <td><input type="checkbox" id="cbox1" name="cbox1" value="cbox1" />Checkbox 1<br /></td> <td><input type="checkbox" id="cbox2" name="cbox2" value="cbox2" />Checkbox 2<br /></td> </tr> <tr> <td> <select id="ddlSelect"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> </td> <td> </td> </tr> <tr> <td>Result:</td> <td><input type="text" id="result" name="result" /></td> </tr> </table> <input type="submit" id="btn_sub" name="btn_sub" value="Submit" onclick="calculate()" /> <input type="reset" id="btn_res" name="btn_res" value="Reset" /> </body> </html> I'm decent at JavaScript but I have no idea how I should go about making a calculator. So far I'll drop a bunch of buttons down that all onclick to a function (a,b) and then it will add or w/e then return. How would I incorporate multiple methods such as subtraction or multiplication though? Basically I'm confident I the ability to code or learn to make this calculator, just have no idea how to set this up, thanks. i am building/coding a simple calculator and i have this Code: function addDigit() { if(id=7) { document.getElementById("display").value="7"; } if(id=8) { document.getElementById("display").value="8"; } if(id=9) { document.getElementById("display").value="9"; } } function clearAll() { document.getElementById("display").value=""; } as the code but when i press the 7 8 or 9 buttons it only shows up as a 9. go to http://www.mightypeacock.com/Practice/calculator.html to see what i mean. already solved
I'm currently revamping a website that was written in aspx. The problem i'm having is that the webpage is moving to a hosting company that doesn't support asp. I'm wanting to rebuild the calculator in javascript, however I have no javascript experience. I can figure some parts of the code out, however I don't really have time to learn it, and was wondering if someone would be willing to help. The site i'm trying to change is: http://sunflowertitle.com/ratecalculator.aspx It shouldn't be that difficult to rebuild as its not a detailed calculator. I have all the original files if anyone needs them, i've been working on this for awhile and i'm to the point i'd be willing to pay someone to build it. I need help trying to figure out how to get my bmi calculator to work. I cant figure out what is wrong with my formula part and why it wont calculate the numbers you type in...pls help! <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript"> function calculateBMI() { var weight = numb(document.data.weight.value) var height = numb(document.data.height.value) var height2 = height2 * height2 var BMI = weight * 703 / (height2 * height2) document.form.BodyMassIndex.value=custRound(BMI,1); } </script> <title></title> <style type="text/css"> div.c2 {text-align: center} input.c1 {font-size: 8pt} </style> </head> <body> <div class="c2"> <form name="form" id="form"><input type="text" name="weight" size="4"> Weight (in Kilos) <input type="text" name="height" size="4"> Height (in Centimeters)<br> <br> <input type="text" name="BodyMassIndex" id="BodyMassIndex" size="4"> BMI <input type="button" class="c1" value="Calculate" onclick="calculateBMI()" name="button"> <input type="reset" class="c1" value="Clear Form"></form> </div> </body> </html> aaaaaa
Hello guys, long story short my boss wants me to add this calculator form to our website(here is the link to what he wants exactly) so I try to copy that code but it won't work. I was wondering if this javascript would work. Code: Code: <script language="JavaScript"> function calc() { gear = document.name1.drpPumpType.1; vane = document.name1.drpPumpType.2; if (gear) { txtW = document.form1.txtW.value; txtD = document.form1.txtD.value; txtL = document.form1.txtL.value; int gearCIR; gearCIR = 6 * txtW *(2 * txtD - txtL) * (txtL - txtD) / 2; } else { int vaneCIR; vaneCIR = 12 * txtW * (txtL + txtD) / 4 * (txtL - txtD) / 2; } I probably don't even need a if statement but I haven't program in a long time and never use java script before. so bare with me. here is the html form code Code: Code: <form name="name1"> <table align="center" border="0" width="44%"> <tbody> <tr> <td colspan="3"><span class="BoldHeadingLabel style1">Displacement from Measurements</span></td></tr> <tr> <td width="50"><span class="style1"></span><br /> </td> <td width="157"><span class="BoldLabel style1">Pump/Motor Type:</span></td> <td width="456"> <span class="style1"></span> <br /> </td></tr> <tr> <td width="50"><span class="style1"></span><br /> </td> <td width="157"><span class="BoldLabel style1">Gear Width (W):</span></td> <td><span class="style1"><input name="txtW" id="txtW" maxlength="10" size="10" value="" type="text" /></span></td></tr> <tr> <td width="50"><span class="style1"></span><br /> </td> <td width="157"><span class="BoldLabel style1">Gear Bore Dia. (D):</span></td> <td><span class="style1"><input name="txtD" id="txtD" maxlength="10" size="10" value="" type="text" /></span></td></tr> <tr> <td width="50"><span class="style1"></span><br /> </td> <td width="157"><span class="BoldLabel style1">Bore to Bore (L):</span></td> <td><span class="style1"><input name="txtL" id="txtL" maxlength="10" size="10" value="" type="text" /></span></td></tr> <tr> <td colspan="3"><span class="style1"></span><br /> </td></tr> <tr> <td width="50"><span class="style1"></span><br /> </td> <td width="157"><span class="BoldLabel style1">Displacement (CIR) = </span></td> <td><span class="CalAnswer style1">_________</span><span class="style1"><br /> </span></td></tr> <tr></tr> <tr> <td colspan="3"><span class="style1"></span><br /> </td></tr> <tr> <td colspan="3" align="center"><input value="Calculate" id="submit1" name="submit1" type="submit" /> <input value="Clear" id="clearform" name="clearform" onclick="cmdReset_onclick()" type="button" /> </td></tr></tbody></table></form> For some reason it says access denied. I copy this code from that website. but can't find any code wrong. I know this code is probably so wrong but any help is much appreciated . I am working on an Mpg calculator and I am stuck any input would be greatly appreciated. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Gas Mileage</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type = "text/javascript"> /*<![CDATA[*/ function calcMPG() { var startMiles= document.forms[0].startingMileage.value; var endMiles= document.forms[0].endingMileage.value; var gallons=document.forms[0].gallons.value; if(isNaN(startMiles) isNaN(endMiles)) isNaN(gallons)) { window.alert("You must enter a number"); } else { if (gallons > 0) { document.forms[0].gallons.value= ((endMiles-startMiles)/gallons).toFixed(1); } } } /*]]>*/ </script> </head> <body> <script type = "text/javascript"> /*<![CDATA[*/ document.write("<p><h1>Miles Per Gallon Calculator</h2></p>"); document.write("<p><h3>You must enter your starting and ending mileage and gallons used.</h3></p>"); /*]]>*/ </script> <form action=""> <p> Starting Mileage<br /> <input type="text" name="startingMileage" value="0" onchange="calcMPG()" /> </p> <p> Ending Mileage <br /> <input type="text" name="endingMileage" value="0" onchange="calcMPG()" /></p> <p>Gallons Used<br /> <input type="text" name="gallons" value="0" onchange="calcMPG()"/></p> <p>Miles Per Gallon<br /> <input type="text" name="miles per gallon" value="0" /></p> </form> </body> </html> I have a mistake when it is suppose to calculate. Thanks to all |