JavaScript - Trying To Get The Age Calculator Work
already solved
Similar TutorialsIt can be found right he http://arkdesigns.ca/AttilaKomaromiJavaCalculator.htm I have javascript enabled on my browsers but it still doesn't work. I see the calculator but pushing the buttons does nothing Any help is appreciated My code is: 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>Javascript Calculator</title> <style> <!-- CSS STYLES GO HERE --> .container { width:500px; height:500px; } .equ { width:99%; height:20px; font-size:20px; text-align:right; margin-bottom:15px; } table { border:1px solid black; padding:5px; width:100%; } table td { margin:3px; text-align:center; width:20%; } .buttons { width:100%; height:50px; font-size:15px; } </style> <script type="text/javascript" src="javascript.js"> </script> </head> <body> <div class="container"> <table cellspacing="0"> <tr> <td colspan="5"><input class="equ" type="input" disabled="disabled" id="equation" value="0"/><input type="hidden" id="previousType" value="-1"/></td> </tr> <tr> <td><input class="buttons" type="button" name="sin" value="sin" onclick="solve ('sin')" /></td> <td><input class="buttons" type="button" name="cos" value="cos" onclick="solve ('cos')" /></td> <td><input class="buttons" type="button" name="tan" value="tan" onclick="solve('tan')" /></td> <td><input class="buttons" type="button" name="sqrt" value="√" onclick="solve('sqrt')" /></td> </tr> <tr> <td><input class="buttons" type="button" name="back" value="←" onclick="remove ();"/></td> <td colspan="2"><input class="buttons" type="button" name="erase" value="C" onclick="clear_equation ();" /></td> <td><input class="buttons" type="button" name="divide" value="/" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="seven" value="7" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="eight" value="8" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="nine" value="9" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="multiple" value="*" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="four" value="4" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="five" value="5" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="six" value="6" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="subtract" value="-" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td><input class="buttons" type="button" name="one" value="1" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="two" value="2" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="three" value="3" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="plus" value="+" onclick="equation (this.value, 1)"/></td> </tr> <tr> <td colspan="2"><input class="buttons" type="button" name="zero" value="0" onclick="equation (this.value, 2)"/></td> <td><input class="buttons" type="button" name="decimal" value="." onclick="equation (this.value, 3)"/></td> <td><input class="buttons" type="button" name="equal" value="=" onclick="solve ('');"/></td> </tr> </table> </div> </body> </html> Thanks to this forum, I finally got my calculator working and want to share it with everyone who can use it. The code below divides the time input by the distance input and displays the resulting pace in a min:sec format. Enter 12 miles, for example, and 1 hour, 33 minutes and 15 seconds, and the code displays 7:46 mpm (minutes per mile). My first version uses one function to do everything, but this morning I decided to teach myself how one function passes stuff to another. So I began trying to perform the min:sec conversion in a function named Pace2minsec and pass the result to the Pace function for display in the form. After several failures, I learned that a function returns its calculation to whatever code calls it. Ah ha, I thought, I need to have Pace call Pace2minsec. Yeah, pretty basic stuff but I am a raw beginner with Javascript, and thought there might be others here like me who could benefit from my mistakes. Even after discovering the call-return process, I had to get the names of the variables correct before it would work. One mistake I made was thinking that I could have a variable with the same name in both functions. Wrong. Even though they were both inside their own function and therefore local variables, apparently, since one function called the other, the names had to be different. In both functions, I had a variable named totalsec, but only when I renamed it totalseconds in the first function did my code work. Another glich was discovering that I had to tell the second function what variable it had to use for its operation. My first stab at that was to put the line Pace2minsec(minsec) in the first function. Wrong. Then I tried Pace2minsec(totalsec). Wrong again. And finally, Pace2minsec(totalseconds) which worked fine. Probably obvious to most, but it sure wasn't to me. Trial and error scripting! But I'm getting there, one principle at a time... <CODE> <html> <head> <script> function Pace(D, H, M, S, form) // Is form really necessary? { var dist = parseFloat(D); // Makes entry a number? var hours = parseFloat(H); var mins = parseFloat(M); var secs = parseFloat(S); var pacedecimal = (hours*60 + mins + secs/60) / dist; // Total minutes in decimal var totalseconds = pacedecimal*60; // Total seconds in decimal form.pace.value =Pace2minsec(totalseconds) + " " + "mpm"; // Tell Pace2minsec what variable to use? } function Pace2minsec(totalsec) { var minsec = ''; sec = Math.round(totalsec%60); // remainder of totalsec div by 60 min = Math.round((totalsec-sec)/60); // total seconds minus remainder minsec = min + (sec>9?":":":0") + sec; // min:sec format adds :0 if sec<10 return(minsec); // Pass min:sec format to Pace, the calling function } </script> </head> <body style="margin-top:100px; text-align:center; font-family:arial; background-color:silver;"> <form name="pacer"> <table style="font-size:14px; font-weight:bold;" cellspacing="0" border="0"> <tr> <td>DIST</td> <td><input type="text" name="dist" size="3"></td> <td width="8"></td> <td>TIME</td> <td><input type="text" name="hours" size="1">:</td> <td><input type="text" name="mins" size="1">:</td> <td><input type="text" name="secs" size="1"></td> <td width="24"></td> <td><input TYPE="button" VALUE="Pace" onClick="Pace(this.form.dist.value, this.form.hours.value, this.form.mins.value, this.form.secs.value, this.form)"></td> <td width="4"></td> <td><input type="text" name="pace" size="8"></td> <td width="6"></td> <td><input TYPE="reset" VALUE="Clear" onClick="clearForm(this.form)"></td> </tr> </table> </form> </body> /html> </CODE> I'm making a calculator with javascript inside of my html, but I can't figure out the right way to produce a working ^ sign. I've searched online for 4 hours now. Does anyone happen to know what I should type? Here's my code Code: <form name="Calc" style="position: fixed; top: 25px; right: 5px; background: #5F4A29;" action=""> <table border="6"> <tr> <td colspan="4"><input type="text" name="Input" size="25" /></td> </tr> <tr> <td><input class="button" type="button" value=" c " onclick="Calc.Input.value = ''" /></td> <td></td> <td></td> <td><input class="button" type="button" value=" = " onclick="Calc.Input.value = eval(Calc.Input.value)" /></td> <tr> </tr> <td></td> <td><input class="button" type="button" value=" ( " onclick="Calc.Input.value += '('" /></td> <td><input class="button" type="button" value=" ) " onclick="Calc.Input.value += ')'" /></td> <td><input class="button" type="button" value=" ^ " onclick="Calc.Input.value += '^(x,y)'" /></td> </tr> <tr> <td><input class="button" type="button" value=" 1 " onclick="Calc.Input.value += '1'" /></td> <td><input class="button" type="button" value=" 2 " onclick="Calc.Input.value += '2'" /></td> <td><input class="button" type="button" value=" 3 " onclick="Calc.Input.value += '3'" /></td> <td><input class="button" type="button" value=" + " onclick="Calc.Input.value += '+'" /></td> </tr> <tr> <td><input class="button" type="button" value=" 4 " onclick="Calc.Input.value += '4'" /></td> <td><input class="button" type="button" value=" 5 " onclick="Calc.Input.value += '5'" /></td> <td><input class="button" type="button" value=" 6 " onclick="Calc.Input.value += '6'" /></td> <td><input class="button" type="button" value=" - " onclick="Calc.Input.value += '-'" /></td> </tr> <tr> <td><input class="button" type="button" value=" 7 " onclick="Calc.Input.value += '7'" /></td> <td><input class="button" type="button" value=" 8 " onclick="Calc.Input.value += '8'" /></td> <td><input class="button" type="button" value=" 9 " onclick="Calc.Input.value += '9'" /></td> <td><input class="button" type="button" value=" * " onclick="Calc.Input.value += '*'" /></td> </tr> <tr> <td></td> <td><input class="button" type="button" value=" 0 " onclick="Calc.Input.value += '0'" /></td> <td><input class="button" type="button" value=" . " onclick="Calc.Input.value += '.'" /></td> <td><input class="button" type="button" value=" / " onclick="Calc.Input.value += '/'" /></td> </tr> </table> </form> This is a code for a simple calculator that requires the input of an Area and then calculates how many packs of product are then required to cover that area, rounding up to the next full pack, The results should be displayed in a simple HTML form but its not happening. I can't see any obvious errors. Am I missing something. Any help or ideas would be greatly appreciated. I might be making this more complicated than necessary. Thanks In the <HEAD> Code: <script> function packCalculation(){ if ( document.getElementById('coverage').value == '' ) { alert('You must enter a number') return false; } var coverage = parseFloat(document.getElementById('coverage').value); //declare coverage variable--> if (isNaN(coverage)) { alert('Please only enter numbers') return false; }; var coverage = parseFloat(document.getElementById('coverage').value); var packSize = parseFloat(document.getElementById('pack-size').innerHTML); var price = parseFloat(document.getElementById('price').value); var packNumFinal = coverage/packSize; <!--work out how many packs are needed--> var finalPrice = packNumFinal*price; <!--work out final price --> document.getElementById('packsNeeded').innerHTML = packNumFinal.ceil(); <!--round up to the next full pack--> document.getElementById('calcPrice').innerHTML = parseFloat(finalPrice).toFixed(2); <!--fix to 2 decimal points--> document.getElementById('results').className='show'; return false; } </script> Then in the <BODY> Code: <form id="packC"> <label>Enter Area to cover ( sq m ):</label> <input type="text" name="coverage" id="coverage" /> <p><span>Pack Coverage (sq m):</span> <span id="pack-size">1.982</span></p> <input type="hidden" name="price" id="price" value="<?php echo $priceFormat; ?>" /> <input type="button" value="Calculate" id="calculate" onclick="packCalculation()"/> <!-- results --> <span class="packs">Packs:</span> <div id="packsNeeded"></div><br/> <span class="cost">Total:</span> <div id="calcPrice"></div> </form> 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 , 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> 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! This is what I have so far, but now I am stuck. My instructor wants the output value (Number Set C) to include Number Set A and Number Set B. For instance, if Number Set A is "10" and you want to add Number Set B whose value is also "10", my instructor wants Number Set C to say "10 + 10 = 20". Where am I going wrong, and what is the easiest way I can make this work while making as little changes as possible? Most of the code is what my instructor requires us to use. Code: <HTML> <HEAD> <TITLE>COMSC-100-1241 - Assignment #8 - Introducing "if" Logic - Programming Your Own Calculator</TITLE> <SCRIPT LANGUAGE="text/JavaScript"> function Go(code){ var a var b var c var x a = parseFloat(document.getElementById("a").value); b = parseFloat(document.getElementById("b").value); if (code == 0){ x = a + b c = a + " + " + b + " = " + x } if (code == 1){ x = a - b c = a + " - " + b + " = " + x } if (code == 2){ x = a * b c = a + " * " + b + " = " + x } if (code == 3){ x = a / b c = a + " / " + b + " = " + x } document.getElementById("c").value = c; } </SCRIPT> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="500" ALIGN="center"> <TR> <TD> <DIV ALIGN="left"> <FORM NAME="calculator"> <B>Instructions: </B> Type a number in the box for "Number Set #1". Then input a <I>second</I> number in the box for "Number Set #2". Click the "Calculate" button, and the sum of those two numbers will appear in the box for "Number Set #3". <BR> <BR> <B>Input Values: </B> <BR> <B>Number Set A:</B> <INPUT ID="a"> <BR><BR> <B>Number Set B:</B> <INPUT ID="b" > <BR><BR> <INPUT TYPE="Submit" VALUE="Add" OnClick="Go(0);"> <INPUT TYPE="Submit" VALUE="Subtract" OnClick="Go(1);"> <INPUT TYPE="Submit" VALUE="Multiply" OnClick="Go(2);"> <INPUT TYPE="Submit" VALUE="Divide" OnClick="Go(3);"> <BR><BR> <B>Output Value: </B> <BR> <B>Number Set C:</B> <INPUT ID="c" SIZE="50"> </FORM> </DIV> </FORM> </TD> </TR> </TABLE> </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> 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 want the calculator to take what was clicked display the item number and also the cost. (if possible i'd like to be able to display cost with no button) sorry if the code is messy i'm new to javascript. Code: <SCRIPT TYPE="TEXT/JAVASCRIPT"> // Definitions var in2 = "" var in3 = "" //costs var $mat = "" var cmat = Number($mat) var $sqft = "" var csf = Number($sqft) var chngcost = cmat*csf var $coga = 30 var $cos = 40 var $coshp = 15 var $total = chngcost + $coga + $cos + $coshp // Add a letter to string function itemnumber2(numb) { in2 = numb document.myform.i2.value = in2 document.itemnumber.i2.value = in2 if (in2 == "10") { $mat = 3 document.myform.cmat1.value = $mat } if (in2 == "11") { $mat = 6 document.myform.cmat1.value = $mat } if (in2 == "12") { $mat = 12 document.myform.cmat1.value = $mat } } function itemnumber3(numb) { in3 = numb document.myform.i3.value = in3 document.itemnumber.i3.value = in3 if (in3 == "1") { $sqft = 7.5 document.myform.sqrf1.value = $sqft } if (in3 == "2") { $sqft = 5.5 document.myform.sqrf1.value = $sqft } if (in3 == "3") { $sqft = 5 document.myform.sqrf1.value = $sqft } } //total cost function function totalcost() { ttc1 = $total document.myform.ttc.value = ttc1 } </SCRIPT> Code: <input type="radio" id="10" name="Size" value="18x22" onclick="itemnumber2(10)"> 18" X 22"<br> <input type="radio" id="11" name="Size" value="24x36" onclick="itemnumber2(11)"> 24" X 36"<br> <input type="radio" id="12" name="Size" value="36x48" onclick="itemnumber2(12)"> 36" X 48"<br> Code: <input type="radio" id="1" name="Material" value="Photo Gloss" onclick="itemnumber3(1)"> Photo Gloss<br> <input type="radio" id="2" name="Material" value="Bond Laminate" onclick="itemnumber3(2)"> Bond Laminate<br> <input type="radio" id="3" name="Material" value="Photo Gloss" onclick="itemnumber3(3)"> Vinyl<br> Code: <form name="itemnumber" action="#"> <span class="style6">Item # <input type="text" size="3" name="i1" value="101" disabled>- <input type="text" size="2" name="i2" disabled>-<input type="text" size="1" name="i3" disabled></span></p> </form> Code: <input name="cost" type="button" onclick="totalcost()" value="Cost"> $<input type="text" size="5" name="ttc" disabled> 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 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? 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 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. 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 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? |