JavaScript - Js Calculator Not Working In Mozilla But Ok In Ie
I have an online calculator in javascript which works in IE but not Moz.
Can anyone help: site: http://www.exigotranslations.com code: function workit() { var xsource = new Array(0,0.09,0.1); // source language var xtarget = new Array(0,0.09,0.10,0.12,0.14); // target language var xtype = new Array(0,0,0.06,0.02,0.06,0.04,0.06,0.03,0.01); // type of text var itemA = parseInt(form1.words.value); if(!itemA){itemA=1}; var itemB = parseInt(form1.source.options[form1.source.selectedIndex].value); var itemC = parseInt(form1.target.options[form1.target.selectedIndex].value); var itemD = parseInt(form1.type.options[form1.type.selectedIndex].value); var total = (itemA*(xtarget[itemC]+xtype[itemD])); if(total < 9) {total = 9}; mytotal.innerHTML = total.toFixed(2); } link to code from webpage is: <script src="Javascript/formcheck.js" type="text/javascript"></script> Can anyone help with what I have done wrong. Thanks, Richard Similar TutorialsI 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 Hello I have been asked by a friend to put together a BMI calculator. I know there are javascript ones already out there that I could use the code for, but a) it needs to do a specific thing b) I am interested in learning a bit of jscript - hence why I just spent about 4hrs trying to get it working You can see what I have been working on here http://www.kubedp.co.uk/bmi2.html Basically - what it needs to do is the following :- - User can either enter Feet/Inches or centimeters for height - User can either enter Stones/Pounds or Kilos for weight. - If they enter Feeet/Inches and centimeters - it throws an error (similar thing for weight). It then outputs the BMI to txtBMIResults. I managed to get the validation working on not having both Stones/Pounds and Kilos filled in etc, but when it comes to the actual calculation - I am stumped. If someone could look at this for me and hopefully code it and comment it so I can understand what has been done to get it working so I might learn, that would be fantastic. http://www.bmi-calculator.net/bmi-formula.php Is the formulas for calculating BMI. Not sure if you can tell from the code - but I was trying to get it so that the calculation was always done on Kilos and Meters, so I was taking the Stones and Pounds and feet and inches and trying to convert it to kilos and metres and then run the calculation. Hope I have been clear. Many thanks for any help anyone can offer HI Friends, I am facing some issue in javascript .my code is working in ie but not in mozilla onkeypress and onkeydown events.please tell me the solution if u knows. my code is givenbellow. in javascript file i have two methods. Code: //========javascript file=========== //will call on keydown function keyCheck(e) { alert('hi---hello --onkeydown'); // var KeyID =(window.event)? event.keyCode : e.which; var browser=navigator.appName; // document.write("Browser name: "+ browser); var asciiValue=event.keyCode; if(asciiValue=='13' || asciiValue=='32'){ return true; } return false; } //call on key press function closePopUpLayer1(e){ alert('hi---onkeypress'); var browser=navigator.appName; document.write("Browser name: "+ browser); unHideDropDownLists(); document.getElementById('popupLayerContent').className="popuplayer"; document.getElementById('mainBody').style.display="none"; document.getElementById('Hotels_TnC_popUp').focus(); } ==============my html file=========== <div> <div class="popup-top-corner-left-img"></div> <div class="popup-top-image"></div> <div class="popup-top-corner-right-img"></div> </div> <div> <div class="popup-left-image"></div> <div class="popup-div1"> <div> <div class="XX-Large-Dark-Gold-popUpText">credit</div> //here i am calling two functions in javascript <div class="sprite-btn-close" id="focusNew1" onkeydown="javascript:return keyCheck(event)" onkeypress="alert('hello');javascript:closePopUpLayer1(event)" onclick="javascript:closePopUpLayer(),document.getElementById('Hotels_TnC_popUp').focus();" ></div> </div> <div class="popup-dark-gray-text">xxxxxdiv> </div> <div class="popup-right-image"></div> </div> <div class="popup-bottom"> <div class="popup-bottom-corner-left-img"></div> <div class="popup-bottom-image"></div> <div class="popup-bottom-corner-right-img"></div> </div> I am having trouble with my calculator not working in Firefox or Flock when it does in IE. I have installed Firebug but my having trouble understanding that - I have not used Mac's, so am not getting anywhere. The web page is http://scubaservice.com.au/Dive-Equi...Insurance.html, the premium calculator is supposed to return 4 values as you enter the equipment value or change the state. Code: function premium_calculator() { var val = document.getElementById('user_input').value; var state = document.getElementById('user_state').value; var excess=[0.03,0.0285714285714286,0.0257142857142857,0.019047619047619]; // excess rates var gst=.10; // GST rate var margin=.60; // margin // state array // var States=["QLD","NSW","ACT","VIC","TAS","SA ","WA ","NT "]; var sd=[0.075,0.09,0.1,0.1,0.08,0.11,0.1,0.1]; // stamp duty rates if (val<100000) { switch (state) { case "QLD": var n1 = val * excess[0]; if (n1 < 75) n1 = 75; var gn1 = n1 * gst; var sd1 = (n1 + gn1) * sd[0]; var m1 = n1 * margin; var mx1 = (val/2500)*((12/36)*25); var gm1 = (m1 + mx1) * gst; var r1 = roundNumber((n1+gn1+sd1+m1+mx1+gm1),2); var n2 = val * excess[1]; if (n2 < 75) n2 = 75; var gn2 = n2 * gst; var sd2 = (n2 + gn2) * sd[0]; var m2 = n2 * margin; var mx2 = (val/2500)*((12/36)*25); var gm2 = (m2 + mx2) * gst; var r2 = roundNumber((n2+gn2+sd2+m2 +mx2+gm2),2); var n3 = val * excess[2]; if (n3 < 75) n3 = 75; var gn3 = n3 * gst; var sd3 = (n3 + gn3) * sd[0]; var m3 = n3 * margin; var mx3 = (val/2500)*((12/36)*25); var gm3 = (m3 + mx3) * gst; var r3 = roundNumber((n3+gn3+sd3+m3+mx3+gm3),2); var n4 = val * excess[3]; if (n4 < 75) n4 = 75; var gn4 = n4 * gst; var sd4 = (n4 + gn4) * sd[0]; var m4 = n4 * margin; var mx4 = (val/2500)*((12/36)*25); var gm4 = (m4 + mx4) * gst; var r4 = roundNumber((n4+gn4+sd4+m4+mx4+gm4),2); break; //this case is repeated for each state with slight differences } } else { alert ("Please contact us for quote"); r1 = 0; r2 = 0; r3 = 0; r4 = 0; } document.getElementById('val_100_1').innerHTML = r1; document.getElementById('val_250_1').innerHTML = r2; document.getElementById('val_500_1').innerHTML = r3; document.getElementById('val_1000_1').innerHTML = r4; } function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength); return newnumber.toFixed(2); // Output the result to the form field (change for your purposes) } Thank you in advance. Hi All, I am using one script which is functioning properly incase of IE but incase of Mozilla evenif the shift key is pressed and any character key is pressed then it is displaying Caps Lock is On. can anyone tell how can I make it Mozilla and IE compatible. Hi All, I am using one script which is functioning properly incase of IE but incase of Mozilla evenif the shift key is pressed and any character key is pressed then it is displaying Caps Lock is On. can anyone tell how can I make it Mozilla and IE compatible. Hi All, This is my first post in this forum. I am relatively new to javascript. Hope I get some guidance here. Also I would like to contribute here when I get little expertise on javascript. I have developed following snippet of code, which is working very well with firefox 6.0. But when it comes to IE 8.0, it just does not work. Quote: <SCRIPT LANGUAGE="JavaScript"> function refreshFrame() { frames['top'].window.location.href = "report.php?parent_id=<? echo $parent_id; ?>"; } </script> </head> <? include('style.php'); include('PHP_functions.php'); print(" <FRAMESET rows='96,100' onLoad=refreshFrame() BORDERCOLOR=blue BORDER=0> <FRAME SRC=blank.html SCROLLING=NO NORESIZE NAME=top> <FRAME SRC=manage.php?view=show_all&parent_id=$parent_id NAME=bottom> </FRAMESET> "); ?> </HTML> In the above script, I am trying to load the frame top after loading frame bottom, as the latter takes more time to load due to some processing involved. Till frame bottom is under processing stage, I display a message "Processing Please wait" which is coming from blank.html. Working under Firefox: It loads blank.html first and displays the message as "processing please wait". Once frame bottom has completed the processing it displays its contents at second half of the webpage. Then finally frame top gets loaded on first half of the web page. This is the expected result. Here URL does not change as the URL remains same as before "http://xyz.com/index.html" Not Working under IE It loads blank.html first and displays the message as "processing please wait". Once frame bottom has completed the processing it displays its contents at second half of the webpage. Then finally frame top gets loaded on whole page instead of first half of the page. Here URL changes to complete new URL as "http://xyz.com/report.php?parent_id" Can anyone please suggest what could be reason for this. Thanks, Vinay 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 Below is the code for a calculator using script. can one help me to explain me the colored line?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> </body> <script language="javascript" type="text/javascript"> function multiply() { a=Number Quote: Quote: (document.calculator.number1.value) ; b=Number(document.calculator.number2.value); c=a*b; document.calculator.total.value=c; } function addition(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a+b; document.calculator.total.value=c; } function subtraction(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a-b; document.calculator.total.value=c; } function division(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a/b; document.calculator.total.value=c; } function modulus(){ a=Number(document.calculator.number1.value); b=Number(document.calculator.number2.value); c=a%b; document.calculator.total.value=c; } </script> </head> <body> <form name="calculator"> Number 1: <input type="text" name="number1"> Number 2: <input type="text" name="number2"> Get Result: <input type="text" name="total"> <input type="button" value="ADD" onclick="javascript:addition();"> <input type="button" value="SUB" onclick="javascript:subtraction();"> <input type="button" value="MUL" onclick="javascript:multiply();"> <input type="button" value="DIV" onclick="javascript:division();"> <input type="button" value="MOD" onclick="javascript:modulus();"> </form> </body> </html> How could i make a calculator that changes three values when a vertex on an image moves. Example : When a point moves on the triangle it changes the cost quality and time. I have this start and need the meat for the concept to work.<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <p><img src="Assets/Project-triangle.svg.png" width="500" height="492" alt=""/>-------------------------------------------<img src="Assets/triangle.gif" width="224" height="210" alt=""/></p> <p> <label for="textfield">Cost :</label> <input type="text" name="textfield" id="textfield"> <label for="textfield2"> Time :</label> <input type="text" name="textfield2" id="textfield2"> <label for="textfield3">Quality :</label> <input type="text" name="textfield3" id="textfield3"> </p> <p> </p> </body> </html> Help would be greatly appreciated! 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'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'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 decent at JavaScript but I have no idea how I should go about making a calculator. So far I'll drop a bunch of buttons down that all onclick to a function (a,b) and then it will add or w/e then return. How would I incorporate multiple methods such as subtraction or multiplication though? Basically I'm confident I the ability to code or learn to make this calculator, just have no idea how to set this up, thanks. i am building/coding a simple calculator and i have this Code: function addDigit() { if(id=7) { document.getElementById("display").value="7"; } if(id=8) { document.getElementById("display").value="8"; } if(id=9) { document.getElementById("display").value="9"; } } function clearAll() { document.getElementById("display").value=""; } as the code but when i press the 7 8 or 9 buttons it only shows up as a 9. go to http://www.mightypeacock.com/Practice/calculator.html to see what i mean. Hi there, me again. Need help with this bit of code. The script itself I got from the JS Source, and modified it myself a bit so that instead of the user inputting their DOB via a prompt box, it could be entered via dropdown lists. I attempted to do this, but have come across a problem. For some reason, the result always (or at least, that's what it looks like to me) appears to be the array index element of [4], i.e. Friday. Not really sure why this is, but no matter what date is entered out of the example dates shown below in the HTML, the result is always Friday. Double-checked on another similiar calculator script online, and sure enough, the results are wrong. So it's a problem with my script. Except I can't identify it. So any help from Old Pedant/Philip M, or whoever else on the forum has the patience to help me , would be much appreciated. Code: <script type="text/javascript" language="javascript"> function findDay() { var arr = new Array(); arr[0] = "Monday"; arr[1] = "Tuesday"; arr[2] = "Wednesday"; arr[3] = "Thursday"; arr[4] = "Friday"; arr[5] = "Saturday"; arr[6] = "Sunday"; var selectdate = document.getElementById("selectdate").selectedIndex; var selectmonth = document.getElementById("selectmonth").selectedIndex; var selectyear = document.getElementById("selectyear").selectedIndex; var birthday = new Date(selectdate + selectmonth + selectyear); var day = birthday.getDay(); document.getElementById("div1").innerHTML = "You were born on a " + arr[day] + "!" } </script> Code: <html> <h1>Day Of The Week?</h1> Input your date of birth, and click the Go button to find out what day of the week you were born on. <hr/> <form style="text-align: center;"> <select id="selectdate"> <option>1</option> <option>2</option> <option>3</option> </select> <select id="selectmonth"> <option>January</option> <option>February</option> <option>March</option> </select> <select id="selectyear"> <option>1995</option> <option>1996</option> <option>1997</option> </select> <br/> <br /> <input align="middle" type="button" value="Go" onclick="findDay()"> </form> <div id="div1"></div> </html> aaaaaa
|