JavaScript - Cost Calculator Help!
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> Similar TutorialsHi there I have tried to work on this code for the last 2 weeks, can not figure out what is wrong with my code, please have a look for me, it will greatly appreciated from me; here my details; I work on <script type="text/javascript" language="javascript"> from dreamweaver to set my code to calculate, different Fiji tour (4 options, choose 1 in options) Payment (4 options, choose 1 in options) The cost of tour - discount base on tour cost. (discount has 4 different calculate) Need to be alert if they not choose 1 in each type. Second cost if they choose to fly out , will cost plus $400 on top the above cost. This is an optional, so they don;t need to buy if they want. I have attached my code, please have a look, Thank you very much I am having troubles with calculating costs on a form. When I press the cost button, it doesn't generate the calculations. Code: var fday = document.getElementById("reg_start_date").value; var lday = document.getElementById("reg_end_date").value; if (fday == "2011-09-05" && lday == "2011-09-06") { cost = cost * 2; } else if (fday == "2011-09-06" && lday == "2011-09-07") { cost = cost * 2; } else if (fday == "2011-09-05" && lday == "2011-09-07") { cost = cost * 3; } I need to implement a function in JavaScript to calculate the total of the purchase which is equal to price of each tool * quantity ordered* sales tax=.08. I also need to use confirm() to display the total cost of the purchase so the user can see it. If my user confirms the order by clicking ok then but clicking cancel will terminate the order. <!DOCTYPE html> <html> <head> <title>Form</title> <meta charset="UTF-8" /> <body> <h1 style="text-align:center"> Hardware Store</h1> <form action="http://www.yahoo.com/formtest.php"> <p> <label> Buyer's Name: <input type="text" name="name" size="30"/> </label> <label> Street Address: <input type="text" name="street" size="30"/> </label> <label> City, State, Zip: <input type="text" name="city" Size="30"/> </label> </p> <table> <tr> <th> Tool Name </th> <th> Price </th> <th> Quantiy </th> </tr> <tr> <td> Hammer </td> <td> $12.00</td> <td> <input type= "text" name="Hammer" size="2" /> </td> </tr> <tr> <td> Shovel </td> <td> $18.00 </td> <td> <input type="text" name="Shovel" size="2" /> </td> </tr> <tr> <td> Trimmer </td> <td> $22.00 </td> <td> <input type="text" name="Trimmer" size="2" /> </td> </tr> </table> <h2> Payment Method </h2> <label> Visa <input type="radio" name="payment" id="payment_visa" value="visa" checked="checked"/> </label> <br /> <label> Mastercard <input type="radio" name="payment" id="payment_mastercard" value="mastercard"/> </label> <br /> <label> American Express <input type="radio" name="payment" id="payment_american_express" value="american express"/> </label> <br /> <input type="submit" value="Submit" /> </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! 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 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'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> 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 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 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. 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> 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 . 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 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 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> 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. |