JavaScript - Js Calculator For Wallpaper Requirements
2nd question here tonight, but ive been at this for days now and need some sort of guidance, so here goes!
Tasked to make a calculator for wallpaper requirements, using javascript. Nothing fancy or extreme, 2 input boxes, one for wall length and one for wall height, hit some sort of button and it will say how many rolls of wallpaper (basic maths im thinking!!) also with the choice of metric or imperial. My head is saying this is easy enought, but ive not a clue how to go about this. Happy to use code from the net but all seem to show proper calculators etc, not really just for an input area with basic maths needed. Any suggestions about how to go about this? Fingers crossed Alan Similar TutorialsI am making my first mobile website and need to put wallpapers in it. I cant make every picture in all resolution for each mobile. I found this website which can auto- resize image when user select their mobile brand...i have tried to learn it from page source but failed. Can any one help me please, m newbie xD here is the website: http://cartoonized.net/cellphone-wallpaper.ph 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! 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> 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> Hi all. I'm having a bit of a problem returning a different value each time a different button is pressed for calculator. What am I doing wrong? Code: <script> function calc(btname){ for(var x=0;x<=11;x++){ if(x==0){ btname="zero"; }else if(x==1){ btname="one"; }else if(x==2){ btname="two"; }else if(x==3){ btname="three"; }else if(x==4){ btname="four"; }else if(x==5){ btname="five"; }else if(x==6){ btname="six"; }else if(x==7){ btname="seven"; }else if(x==8){ btname="eight"; }else if(x==9){ btname="nine"; }else if(x==10){ btname="multiply"; }else if(x==11){ btname="divide"; } if('document.forms.test.'+btname+'.onClick'){ alert(btname); } } } function scalc(){ var sign=""; var btname=""; document.write('<form name="test">'); for(var x=0;x<=11;x++){ if(x==0){ btname="zero"; }else if(x==1){ btname="one"; }else if(x==2){ btname="two"; }else if(x==3){ btname="three"; }else if(x==4){ btname="four"; }else if(x==5){ btname="five"; }else if(x==6){ btname="six"; }else if(x==7){ btname="seven"; }else if(x==8){ btname="eight"; }else if(x==9){ btname="nine"; }else if(x==10){ btname="multiply"; sign = "*"; }else if(x==11){ btname="divide"; sign = "/"; } if(x<10){ document.write('<input type="button" size="30" name="'+btname+'" value="'+x+'" onClick="calc(this);"> '); }else if(x>9 && x<12){ document.write('<input type="button" size="30" name="'+btname+'" value="'+sign+'" onClick="calc(this);"> '); } if(x==2 || x == 5 || x == 8){ document.write('<br>'); } } document.write('</form>'); } scalc(); </script> ANY help is GREATLY appreciated! I 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. 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> 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 . 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. 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'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 already solved
aaaaaa
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 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? 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> |