JavaScript - What Am I Doing Wrong With My Calculator?
I'm trying to get this calculator to work
html Code: <form name="Calc" id="calculator" style="position: fixed; top: 25px; right: 5px; background: #5F4A29;" action=""> <table border="6"> <tr> <td colspan="4"><input type="text" name="Input" size="25" onclick="calc(Calc); return true" /></td> </tr> <tr> <td><input class="button" type="button" name="clr" value="c" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="(" value="(" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name=")" value=")" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="equ" value="=" onclick="calc(Calc)" /></td> </tr> <tr> <td><input class="button" type="button" name="_1" value="1" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_2" value="2" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_3" value="3" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="add" value="+" onclick="calc(Calc)" /></td> </tr> </tr> <tr> <td><input class="button" type="button" name="_4" value="4" onclick="calc(Calc) += '4'" /></td> <td><input class="button" type="button" name="_5" value="5" onclick="calc(Calc) += '5'" /></td> <td><input class="button" type="button" name="_6" value="6" onclick="calc(Calc) += '6'" /></td> <td><input class="button" type="button" name="sub" value="-" onclick="calc(Calc)" /></td> </tr> <tr> <td><input class="button" type="button" name="_7" value="7" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_8" value="8" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="_9" value="9" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="mul" value="*" onclick="calc(Calc)" /></td> </tr> <tr> <td></td> <td><input class="button" type="button" name="_0" value="0" onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="dot" value="." onclick="calc(Calc)" /></td> <td><input class="button" type="button" name="div" value="/" onclick="calc(Calc)" /></td> </tr> </table> </form> and js Code: function calc(Calc) { var add = eval (document.Calc.add.value); var sub = eval (document.Calc.sub.value); var mul = eval (document.Calc.mul.value); var div = eval (document.Calc.div.value); var clr = eval (document.Calc.clr.value); var _0 = eval (document.Calc._0.value); var _1 = eval (document.Calc._1.value); var _2 = eval (document.Calc._2.value); var _3 = eval (document.Calc._3.value); var _4 = eval (document.Calc._4.value); var _5 = eval (document.Calc._5.value); var _6 = eval (document.Calc._6.value); var _7 = eval (document.Calc._7.value); var _8 = eval (document.Calc._8.value); var _9 = eval (document.Calc._9.value); var dot = eval (document.Calc.dot.value); var equ = eval (document.Calc.equ.value) var output=Calc.Input.value=add+sub+mul+div+clr+_0+_1+_2+_3+_4+_5+_6+_7+_8+_9+dot+equ; document.getElementById("calculator").innerHTML=output; } Can someone help me sort this out? Similar TutorialsCode: <script> // Calculate and display the total cost of the selected cruise function CostOfCruise(findRounding) { //Get the varius elements in the statements and variable document.getelementbyID ("costCruise" + i); //Assign a value to the radioButton document.getElementById("returnFare"); //Assign a vlaue to the checkbox document.getElementById("costSeat" + i); //Assign a value to the second radio button document.getElementById ("totalCost"); //Assign a value to the total cost of the cruise document.getElementById("findRounding"); //Assign a rounded value to the total cost //List the variables involved var radioButton; // A radio button var costCruise; //Cost of each cruise var checkbox; //A checkbox var returnFare; //The reutrn fare var radio; //the second set of radio buttons var costSeat; //Cost of seating choice var totalCost; //The final cost of the cruise //Determine the cruise chosen and its cost //Get the cost of the selected cruise for (var i = 1; i <= 5; i++) radioButton = document.getElementById("Costcruise" + i); // Display the appropriate response if (radioButton.value === "") alert("You need to choose one of the islands to visit."); else (radioButton.checked === true); //Get the cost of the cruise as a whole number costCruise *= parseInt(radioButton.value); //Determine if return fare purchased // Check if the object is valid before attempting to use it if (returnFare.value === null) return; else (checkbox.checked === true); checkbox = document.getElementById("returnFare"); //Get the value of the reutrn fare as a whole number returnFare *= parseInt(checkbox.value); //Determine which type of seating chosen if (radio.value === "") alert("You need to choose your preferred seating arrangements."); else (radio.checked === true); radio = document.getElementById("costSeat" + i); //Get the cost of the seating as a whole number costSeat *= parseFloat(radio.value); //Calculate total cost of cruise totalCost = document.getElementById ("totalCost"); totalCost = ("costCruise" * "returnFare") * "costSeat"; //Total Cost of cruise //rounds the cost to its nearest integer findRounding = document.getElementById("findRounding"); findRounding = Math.round("totalCost"); alert ("The total cost of this cruise is $" + findRounding); } </script> <html> body> <h1>Island Hopper Cruises Fare Calculator</h1> <p> Complete the form below to calculate the cost of your cruise.</p> <form> <!--The choices of islands to visit with their assigned values or cost of the trip.--> <p>Route:<br /> <input type="radio" id="cruise1" name="costCruise" value="49"> <label for="cruise1">Main Beach - Azkaban Island</label><br> <input type="radio" id="cruise2" name="costCruise" value="79"> <label for="cruise2">Main Beach - Amity Island</label><br> <input type="radio" id="cruise3" name="costCruise" value="109"> <label for="cruise3">Main Beach - Treasure Island</label><br> <input type="radio" id="cruise4" name="costCruise" value="89"> <label for="cruise4">Main Beach - Gilligan's Island</label><br> <input type="radio" id="cruise5" name="costCruise" value="59"> <label for="cruise5">Main Beach - Skull Island</label><br></p> <!--The decision to purcahse a return fare or not.--> <p> Click here if you will be purchasing a return fa <input type="checkbox" id="returnFare" name="returnFare" value="2"></p> <!--The choice of seating arrangment and their assigned value according to class of seat.--> <p>Seating:<br /> <input type="radio" id="first" name="costSeat" value="2.5"> <label for="first">First class</label><br> <input type="radio" id="busi" name="costSeat" value="1.5"> <label for="busi">Business class</label><br> <input type="radio" id="econ" name="costSeat" value="1"> <label for="econ">Economy class</label><br></p> <!--The total cost of the chosen trip displayed as an alert.--> <input type="button" value="Calculate" onclick="CostOfCruise"> <input type="reset" value="Reset"> </form> </body> </html> Hello! I have a really simple JavaScript calculator I'm running, and for the life of me can not figure out how to solve this crazy number problem. It's not doing the math properly, and javascript is not my strongest suit. All my script does is take user input of numbers into a form field, subtract that from another form and multiply the answer of those two forms by whatever the user put in. Example: 210 (minus) 120 (multiplied by) .90 = 81 Here is the actual script: Code: // Calculator function CalculateSum(Atext, Btext, Ctext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); var C = parseFloat(Ctext); form.Answer.value = A - B * C; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.input_C.value = ""; form.Answer.value = ""; } // end of JavaScript functions --> And the html I am using: Code: <form name="Calculator" method="post"> <p>Base Average<input type=text name="input_A"></p> <p>Current Average:<input type=text name="input_B"></p> <p>Percentage of:<input type=text name="input_C"></p> <p>Your ball speed is: (miles per hour) <input name="Answer" type=text readonly> </p> <p> <input type="button" value="Calculate Handicap" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form)"> <input type="button" value="Clear" name="ClearButton" onClick="ClearForm(this.form)"> </p> </form> Any 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! 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> 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> 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! 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 So after some studying I have a pretty decent method using objects. I built it so that you hit the first number, then you would hit a plus or minus then the second number. The problem is just getting the buttons to define variables and run functions. Quote: <html> <head> <script type="text/javascript" > x=10; h=1; var numbs = new Const(x) function Const(one){ this.x=one; ADD(this.x) if(h=1){ function ADD(a){ y=5; b=y+a; alert(b); }}} </script> </head> <body> <input type="button" value="1" onclick="needs to run all that AND set x=1 and h=1"> </body> </html> Also I plan on going back and making y, which is the second number you're adding, an object. For now I'm just setting it equal to something so I don't have to mess with it. already solved
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 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> 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. aaaaaa
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> Hi everyone, I am currently doing a project with a calculator and I am having a bit of trouble trying to figure something out and was wondering if I could get some help with it or possibly even a good site to read up on it. I am trying to make it so my calculator is disabled on startup. I can only seem to get my textbox disabled but I need everything disabled except the ON button.. so whey they click the ON button everything is enabled. when they click the OFF button everything is wiped and disabled.. I'm not to familiar with that yet so all the help is greatly appreciated.. I'm not sure if I'm going on the right direction with this but heres my code... Code: var value function start() { form1.tb1.disabled = true; } onload = start; function enable() { form1.tb1.disabled = false } function shownumber(value){ document.form1.tb1.value=document.form1.tb1.value+value document.form1.plus.disabled=false document.form1.minus.disabled=false document.form1.times.disabled=false document.form1.divide.disabled=false } function showoperator(value){ document.form1.tb1.value=document.form1.tb1.value+value } function evalit(){ document.form1.tb1.value=eval(document.form1.tb1.value) } and my body is Code: <table width="210" border="1" bgcolor="#0000"> <form name="form1"> <tr> <td align="center"> <table width="173" border="0" cellspacing="0" cellpadding="0" height="130"> <tr> </tr> <tr> <td colspan="3"> <input type="text" name="tb1" size="20"> </td> <td width="53" height="0"> <font color="#FFFFFF"> <input type="button" name="clear" value=" c " onClick="document.form1.tb1.value=''"> </font></td> </tr> <tr> <td width="53" height="0"> <input type="button" name="7" value=" 7 " onClick="shownumber('7')"> </td> <td width="53" height="0"> <input type="button" name="eight" value=" 8 " onClick="shownumber('8')"> </td> <td width="53" height="0"> <input type="button" name="nine" value=" 9 " onClick="shownumber('9')"> </td> <td width="53" height="0"> <font color="#FFFFFF"> <input type="button" value=" / " name="divide" onClick="showoperator('/')"> </font></td> </tr> <tr> <td width="53" height="0"> <input type="button" name="four" value=" 4 " onClick="shownumber('4')"> </td> <td width="53" height="0"> <input type="button" name="five" value=" 5 " onClick="shownumber('5')"> </td> <td width="53" height="0"> <input type="button" name="six" value=" 6 " onClick="shownumber('6')"> </td> <td width="53" height="0"> <font color="#FFFFFF"> <input type="button" name="times" value=" x " onClick="showoperator('*')"> </font></td> </tr> <tr> <td width="53" height="0"> <input type="button" name="one" value=" 1 " onClick="shownumber('1')"> </td> <td width="53" height="0"> <input type="button" name="two" value=" 2 " onClick="shownumber('2')"> </td> <td width="54" height="0"> <input type="button" name="three" value=" 3 " onClick="shownumber('3')"> </td> <td width="72" height="0"> <font color="#FFFFFF"> <input type="button" name="minus" value=" - " onClick="showoperator('-')"> </font></td> </tr> <tr> <td width="53" height="0"> <input type="button" name="zero" value=" 0 " onClick="shownumber('0')"> </td> <td width="53" height="0"> </td> <td width="54" height="0"> <input type="button" value=" + " name="plus" onClick="showoperator('+')"> </td> <td width="72" height="0"> <font color="#FFFFFF"> <input type="button" name="calculate" value=" = " onClick="evalit()" </font></td> <tr> <td> <input type="button" id="but1" value="On" onClick="enable();"> <input type="button" id="button2" value="Off"> </td> </tr> </table> </td> </tr> </form> </body> </html> 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. Hi there, me again. Need help with this bit of code. The script itself I got from the JS Source, and modified it myself a bit so that instead of the user inputting their DOB via a prompt box, it could be entered via dropdown lists. I attempted to do this, but have come across a problem. For some reason, the result always (or at least, that's what it looks like to me) appears to be the array index element of [4], i.e. Friday. Not really sure why this is, but no matter what date is entered out of the example dates shown below in the HTML, the result is always Friday. Double-checked on another similiar calculator script online, and sure enough, the results are wrong. So it's a problem with my script. Except I can't identify it. So any help from Old Pedant/Philip M, or whoever else on the forum has the patience to help me , would be much appreciated. Code: <script type="text/javascript" language="javascript"> function findDay() { var arr = new Array(); arr[0] = "Monday"; arr[1] = "Tuesday"; arr[2] = "Wednesday"; arr[3] = "Thursday"; arr[4] = "Friday"; arr[5] = "Saturday"; arr[6] = "Sunday"; var selectdate = document.getElementById("selectdate").selectedIndex; var selectmonth = document.getElementById("selectmonth").selectedIndex; var selectyear = document.getElementById("selectyear").selectedIndex; var birthday = new Date(selectdate + selectmonth + selectyear); var day = birthday.getDay(); document.getElementById("div1").innerHTML = "You were born on a " + arr[day] + "!" } </script> Code: <html> <h1>Day Of The Week?</h1> Input your date of birth, and click the Go button to find out what day of the week you were born on. <hr/> <form style="text-align: center;"> <select id="selectdate"> <option>1</option> <option>2</option> <option>3</option> </select> <select id="selectmonth"> <option>January</option> <option>February</option> <option>March</option> </select> <select id="selectyear"> <option>1995</option> <option>1996</option> <option>1997</option> </select> <br/> <br /> <input align="middle" type="button" value="Go" onclick="findDay()"> </form> <div id="div1"></div> </html> I have a formula done in PHP. Lets say it's PHP Code: $sum = $_POST['one'] + $_POST['two']; I have 2 textboxes, one named "one", the other named "two". I want the page to also display the answer under the text boxes but it updates in real time when you input a value into the textboxes. How would I do that? |