JavaScript - Javascript Helppp Gpa Calculator
Hi!
I have this java script function to set up a GPA calculator. There's something wrong, but I can't figure out what, any answers? Thanks! var GPA=new Array("F","F","F","F","F"); var GPA=new Array("D","D","D","D","D"); var GPA=new Array("C","C","C","C","C"); var GPA=new Array("C+","C+","C+","C+","C+"); var GPA=new Array("B","B","B","B","B"); var GPA=new Array("B+","B+","B+","B+","B+"); var GPA=new Array("A","A","A","A","A"); var credits=new Array(0,0,0,0,0); var credits=new Array(1,1,1,1,1); var credits=new Array(2,2,2,2,2); var credits=new Array(3,3,3,3,3); var credits=new Array(4,4,4,4,4); var GPA_point=new Array(0,0,0,0,0); var GPA_point=new Array(5,5,5,5,5); function get GPA point(gpa){ if(gpa=="A"||gpa=="a") return 4; else if(gpa=="B+"||gpa=="b+") return 3.5; else if(gpa=="B"||gpa=="b") return 3; else if(gpa=="C+"||gpa=="c+") return 2.5; else if(gpa=="C"||gpa=="c") return 2; else if(gpa=="D"||gpa=="d") return 1; else if(gpa=="F"||gpa=="f") return 0; } function calculate_gpa(){ var totalGPA=0; var total_credits =0; for(var i=0;i<5;i++){ GPA_point[i]=get_GPA_point(GPA[i]); totalGPA = totalGPA + GPA_point[i]*credits[i]; total_credits = total_credits + credits[i]; } if(total_credits==0) document.getElementById("gpa_result").value = 0; else document.getElementById("gpa_result").value = (totalGPA/total_credits).toFixed(1); } Similar TutorialsI'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 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> 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> 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> aaaaaa
I've seen several Java or Perl Derivative Calculators online, but I can't seem to find any in JavaScript. Has anyone tried? I might need one in JavaScript (or Flash ActionScript) for a graphing tool I'm working on, and I don't want to reinvent the wheel if I can avoid it.
I'm new to javascript but not to programming. Here is my code: PHP Code: PHP Code: print "<form name='goldcalculator'>"; print "<input type='hidden' name='goldspot' value='$goldvalue'>"; print "<select name='gunit' onchange='updateTotal();'>"; print "<option value='20'>Pennyweight (DWT)</option>"; print "<option value='31.1'>Grams (g)</option>"; print "</select><br>"; print "10K <input type='text' name='10k' onchange='updateTotal();'><br>"; print "14K <input type='text' name='14k' onchange='updateTotal();'><br>"; print "18K <input type='text' name='18k' onchange='updateTotal();'><br>"; print "22K <input type='text' name='22k' onchange='updateTotal();'><br>"; print "24K <input type='text' name='24k' onchange='updateTotal();'><br>"; print "TOTAL <input type='text' name='totalprice'>"; print "</form>"; Code: <script language="JavaScript"> function updateTotal() { var u = document.goldcalculator.gunit.value; var spotprice = document.goldcalculator.goldspot.value / u; var gold10 = document.goldcalculator.10k.value; var gold14 = document.goldcalculator.14k.value; var gold18 = document.goldcalculator.18k.value; var gold22 = document.goldcalculator.22k.value; var gold24 = document.goldcalculator.24k.value; var calculatedPrice = document.goldcalculator.totalprice.value; calculatedPrice = ((spotprice*.999*gold24)+(spotprice*.916*gold22)+(spotprice*.75*gold18)+(spotprice*.585*gold14)+(spotprice*.417*gold10)); } </script> I don't know where to begin to debug this. It's very simple. The $goldvalue variable is non-editable and is pulled off my MySQL database and that works. They fill in the inputs via the PHP form and then it basically adds them up and spits out the total. Can someone tell me what's wrong? Hello everyone, wondering if I could get some help. I have not done anything with html and javascript until this afternoon and funnily enough I'm struggling a tad I am creating a free website about the dangers of chocolate for dogs. Basically I need a calculator to calculate the toxic amount for the user input of their dogs weight in kgs. I figured doing one for each type of chocolate would be easier than doing something where a box was ticked for each type of chocolate so have been trying to do one for milk chocolate first. This is my feeble attempt, it looks good but doesnt work, my javascript is clearly majorly wrong somewhere! <html> <head> <script language="JavaScript"> function calc(form) { var f = parseFloat(form.kg.value); var T = 0; T = (f/0.45)*28.35; form.answer.value = T; } // done hiding from old browsers --> </script> </head> <body> <FORM> <h2>Toxic dose of milk chocolate</h2> Enter dogs weight in kg: <INPUT NAME="kg" VALUE="0" MAXLENGTH="100" SIZE=25> <p> Click to calculate toxic dose in grammes: <INPUT NAME="calc" VALUE="Calculate" TYPE=BUTTON onClick=kg(this.form)> <p> Toxic amount of milk chocolate is: <INPUT NAME="g" READONLY SIZE=25> </FORM> </body> </html> Can anybody help? Thanks in advance. I'm just learning javascript and am editing a calculator form that will calculate square footage and write to a form text field. I have another form filed that I would like to display a number based a series of if else statements. ex: if square footage > 2761 then display 5.0., if square footage > 2521 then display 4.5. etc. Any help would be appreciated. I have posted my the code below. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<HTML> <HEAD> <TITLE>Size Calculator</TITLE> <SCRIPT LANGUAGE="JavaScript"> function CalculateSum(Atext, Btext, form) { var A = parseFloat(Atext); var B = parseFloat(Btext); form.Footage.value = A * B; form.Size.value = 21; } /* ClearForm: this function has 1 argument: form. It clears the input and answer fields on the form. It needs to know the names of the INPUT elements in order to do this. */ function ClearForm(form) { form.input_A.value = ""; form.input_B.value = ""; form.Footage.value = ""; form.Size.value = ""; } // end of JavaScript functions --> </SCRIPT> </HEAD> <BODY> <P><FONT SIZE="+2">Sizing Calculator</FONT></P> <FORM NAME="Calculator" METHOD="post"> <P>House width (ft): <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P> <P>House length (ft): <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P> <P><INPUT TYPE="button" VALUE="Calculate" name="Calculate" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form)"></P> <P><INPUT TYPE="button" VALUE="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></P> <P>Square footage = <INPUT TYPE=TEXT NAME="Footage" SIZE=12></P> <P>Size = <INPUT TYPE=TEXT NAME="Size" SIZE=12></P> </FORM> </BODY> </HTML> I need help putting parentheses in my calculator. Could anyone provide me some source code for parentheses in a calculator? If not source code, could you offer me recommendations as to how to solve my problem? Thanks! Hi, I am new to Javascript and I am having a problem with this calculator I am building. The purpose is to see if you will be able to go to prom. In a form you input 4 pieces of info. (1)How much money the ticket costs. (2)How much money your tuxedo costs. (3)How much money the dinner costs. (4)How much money you have. I have the calculator set up, and it is supposed to add together the ticket cost, tuxedo cost, and dinner cost, and subtract it from how much money you have. I finished the code, and I am getting no error at the bottom of the screen, but the calculator doesn't work. So, I guess it is a logic error. Here is the code and a link to the page: http://themusiccove.com/Documents/prom2010.htm <html> <head> <title>Prom 2010</title> <script LANGUAGE="JAVASCRIPT"> function prom(myform) { var ticket=document.Calculator.ticket.value var ticket=parseInt(ticket,10) if (isNaN(ticket)) { alert("Enter a number for the Ticket Cost.") document.Calculator.ticket.value="" document.Calculator.ticket.focus() } else { var tuxedo=document.Calculator.tuxedo.value var tuxedo=parseInt(tuxedo,10) if (isNaN(tuxedo)) { alert("Enter a number for the Tuxedo Cost.") document.Calculator.tuxedo.value="" document.Calculator.tuxedo.focus() } else { var dinner=document.Calculator.dinner.value var dinner=parseInt(dinner,10) if (isNaN(dinner)) { alert("Enter a number for the Dinner Cost.") document.Calculator.dinner.value="" document.Calculator.dinner.focus() } else { var money=document.Calculator.money.value var money=parseInt(money,10) if (isNaN(money)) { alert("Enter a number for how much money you have.") document.Calculator.money.value="" document.Calculator.money.focus() Calculate=money-(ticket+tuxedo+dinner) document.Calculator.answer.value=Calculate } } } } } </script> </head> <body bgcolor="ccffcc"> <img src="http://www.shop-direct.net/images/prom5.jpg" align="left" width="125" length="100"> <img src="http://www.packerpress.com/wp-content/uploads/2009/05/5301-men-tuxedo-jacket-b.jpg" align="right" width="125" length="100"> <h2><center>Prom Calculator</center><h2> <h4><center>Enter the data in the textboxes to see if you have enough money to go to prom.</center></h4> <Center><FORM Name="Calculator"> <table border="0"> <tr> <td><p align=right>Ticket Cost: </td> <td><Input Type="text" Name="ticket" value=" "></td> </tr> <tr> <td><p align=right>Tuxedo Cost: </td> <td><Input Type="text" Name="tuxedo" value=" "></td> </tr> <tr> <td><p align=right>Dinner Cost: </td> <td><Input Type="text" Name="dinner" value=" "></td> </tr> <tr> <td><p align=right>Your Money: </td> <td><Input Type="text" Name="money" value=" "></td> </tr> <tr> <td><p align=right>Profit/Loss: </td> <td><Input Type="text" Name="answer" value=" "></td> </tr> <tr align="center"> <td colspan=2><Input Type="Button" Value="Calculate" Onclick="prom(Calculator)"></tr> <tr align="center"><td colspan=2><Input Type="Reset"></td></tr> </table></center> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers //--> </SCRIPT> <CENTER><HR Width="75%"></CENTER> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers var tNow = new Date() var tlocDate = tNow.toLocaleString() var tDate = tlocDate.substring(0,23) document.write("<H2><CENTER>Welcome, today is "+tDate+"</CENTER></H2>") //--> </SCRIPT> <SCRIPT LANGUAGE="JAVASCRIPT"> <!--Hide from old browsers document.write("<H4><CENTER>This document was last modified "+document.lastModified+"</CENTER></H4>") //--> </SCRIPT> </body> </html> hey guys, I have to create a scientific calculator using javascript and I am wondering how I can make it so that the equals box (box that displays the answer) cannot be manually cleared with the mouse cursor. thanks! Scott Hi there, me again, lol. I'm now working on a simple JavaScript calculator script, and here's what I have so far. 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>Untitled Document</title> </head> <body> <form name="Calculator"> <input type="text" name="Output" size="22"> <br/> <br/> <input name="1" type="button" value=" 1 " onClick="document.Calculator.Output.value += '1'" /> <input name="1" type="button" value=" 2 " onClick="document.Calculator.Output.value += '2'" /> <input name="1" type="button" value=" 3 " onClick="document.Calculator.Output.value += '3'" /> <input name="1" type="button" value=" 4 " onClick="document.Calculator.Output.value += '4'" /> <br/> <input name="1" type="button" value=" 5 " onClick="document.Calculator.Output.value += '5'" /> <input name="1" type="button" value=" 6 " onClick="document.Calculator.Output.value += '6'" /> <input name="1" type="button" value=" 7 " onClick="document.Calculator.Output.value += '7'" /> <input name="1" type="button" value=" 8 " onClick="document.Calculator.Output.value += '8'" /> <br/> <input name="1" type="button" value=" 9 " onClick="document.Calculator.Output.value += '9'" /> <input name="1" type="button" value=" 0 " onClick="document.Calculator.Output.value += '0'" /> <input name="1" type="button" value=" + " onClick="document.Calculator.Output.value += ' + '" /> <input name="1" type="button" value=" - " onClick="document.Calculator.Output.value += ' - '" /> <br/> <input name="1" type="button" value=" C " onClick="document.Calculator.Output.value = ''" /> <input name="1" type="button" value=" / " onClick="document.Calculator.Output.value += ' / '" /> <input name="1" type="button" value=" * " onClick="document.Calculator.Output.value += ' * '" /> <input name="1" type="button" value=" = " onClick="document.Calculator.Output.value += ' = ' + eval(Calculator.Output.value)" /> </form> </body> </html> The calculator itself is fully working functionally, feel free to test to your heart's content. :P The problem I'm having is not really a problem per se, more of a behaviour I don't want in the script. After clicking the = button and getting the results of the calculation displayed, clicking another number will just concatenate (I believe that's the right term) that to the result of the sum, and I don't want this to happen. If I've just done a calculation, I want the results of it to be cleared as soon as I hit another button. My guesses are that I would need to do this via some function activated by the = button. Is there some sort of way I can have the output of a sum cleared after a calculation has been done, so that the next calculation becomes a seperate one? If you're still not getting what I'm saying entirely, just let me know, I will try to provide screenshots. Thanks. I am no JavaScript guru but I am trying to make a form that will calculate a discount if the quantity is greater than 4. I need it to also calculate a total with discounts at the very end. I have the discount working but I need it to work over multiple fields. Any help would be greatly appreciated. I have been pulling my hair out over this one for 3 days. Thanks in advance. Here is the code. Code: <html> <header> <SCRIPT type = "text/JavaScript"> function calcPrice(){ var discount, price, total, savings; var v = parseInt(document.getElementById("value").value); var q = parseInt(document.getElementById("quantity").value); if (q <= 3) discount = 0; else if (q>=4) {discount = .25} price = q * v; savings = q * v * discount; total = q * v - savings; alert(total); } </SCRIPT> Number of Bedrooms <input type="text" id="quantity" /> <input type="hidden" id="value" value="10" /> <input type="button" onclick="calcPrice()"> </header> <body> </body> </html> I am trying to build a direct mail calculator and am taking it one step at a time. I am stuck because I need to calculate postage based on quantity entered and what size mailer they have chosen. Any help is greatly appreciate as I am a novice! So far I have (PLEASE NOTE the array of printing_cost_formulas are just random numbers I put to check it worked): Code: <script type="text/javascript"> var printing_cost_formulas = new Array(); printing_cost_formulas["4x6"]=10+5; printing_cost_formulas["5.5x8.5"]=25; printing_cost_formulas["6x9"]=35; function getPrintingCost() { var PrintingCost=0; var theForm = document.forms["cakeform"]; var mailertype = theForm.elements["mailertype"]; for(var i = 0; i < mailertype.length; i++) { if(mailertype[i].checked) { PrintingCost = printing_cost_formulas[mailertype[i].value]; break; } } return PrintingCost; } function calculateTotal() { var PrintingCost = getPrintingCost(); var divobj = document.getElementById('totalPrice'); divobj.style.display='block'; divobj.innerHTML = "Total Printing Cost $"+PrintingCost + mailer_quantity; } </script> So, as an example I need help starting down a path of defining when the user wants 1,000 of 4x6 the price is 0.50 per piece. When they want 1,000 6x9 the price is 0.55 and so on. All the postage variables are known I just have no idea how to write the 'if, else' statement or define the quantity variable within this context!! AH! Greetings all, I need someone to help me out with this code for a project, i need to calculate monthly payments and total payments based off starting and ending interest rates and including the number of years to borrow. I'm stuck with the calculations below, can someone please put me in the right direction when it comes down to the calculations. <html> <head> <title></title> <script type="text/javascript"> function calcPayment() { var loanamount = parseInt (document.getElementById ("loanAmt").value); var startinterest = parseInt (document.getElementById ("startRate").value); var endinterest = parseInt (document.getElementById ("endRate").value); var years = parseInt (document.getElementById ("loanYears").value); var //construct table var msg = "<table border='3' width='90%'>"; msg += "<tr>"; msg += "<td>Interest Rate</td>"; msg += "<td>Monthly Payment</td>"; msg += "<td>Total Payament</td>"; msg += "</tr>"; for (var i = startinterest; i <= endinterest; i+= 0.25) { msg += "<td>" + i + "</td>"; msg += "<td>" + Math.pow( i, 2) + "</td>"; msg += "<td>" + Math.sqrt( i) + "</td>"; msg += "</tr>"; } msg += "</table>"; document.getElementById("results").innerHTML = msg } </script> <style type="text/css"> body { background: black; color: blue; text-align: center; } #maintitle { color: red; font-size: 2em; font-weight: bold; } .infostyle { border-bottom: 5px red double; padding-bottom: 5px; } #infowrap { background-color: #FFFF99; border: 5px red solid; padding: 20px; margin: 20px 100px 50px 100px; height: 350px; } #contentwrap2 { background-color: #FFFF99; border: 5px white solid; margin-top: 65px; margin-left: -25px; margin-right: -25px; padding: 150px; } .formtext { font-size: 1.25em; font-weight: bold; margin-top: 20px; } #results { color: #339900; font-weight: bold; font-size: 2em; margin-top: -50px; margin-bottom: -50px; margin-left: -50px; } #spacer { margin-bottom: 5px; } </style> </head> <body> <div id="contentwrap1"> <div id="infowrap"> <div id="maintitle" class="infostyle"> Javascript Loan Calculator </div> <form> <div class="formtext" > Enter initial loan amount: </div> <input type="text" id="loanAmt" /> <div class="formtext"> Enter starting interest rate:</div> <input type="text" id="startRate" /> <div class="formtext"> Enter ending interest rate:</div> <input type="text" id="endRate" /> <div class="formtext"> Enter how many years to borrow:</div> <input type="text" id="loanYears" /> <div style="margin-top:5px;"> <input type="button" value="Compute monthly payments" onClick="calcPayment()"/> </div> </form> <div id="contentwrap2"> <div id="results"> </div> </div> </div> </body> </html> Hiya, Got a form located at the following link: http://www.boostcreative.com/MA/ In short, trying to make it so that the user can type multiple numbers into the various fields and in real time they add up. If it hits the magic number, they can submit the form. The problem I'm having is the form validation. Any thoughts as to how I would set it so that the form is only submitted if the magic number is reached? (In this case 200) Thanks! Code: $(document).ready(function(){ $(".addition").each(function() { $(this).keyup(function(){ calculateSum(); }); }); }); function calculateSum() { var sum = 0; $(".addition").each(function() { if(!isNaN(this.value) && this.value.length!=0) { sum += parseFloat(this.value); if ( sum == 200 ) { $('#negative').hide();$('#positive').show();} if ( sum != 200 ) { $('#negative').show();$('#positive').hide();} } }); $("#sum").html(sum.toFixed(0)); } function validateForm() { var total = 0; $(".addition").each(function() { if(!isNaN(this.value) && this.value.length!=0) { total += parseFloat(this.value); if ( total != 200 ) { alert("That Total is incorrect"); return false; } } Code: <form method="post" action="contactForm.php" name="MAloyalty" id="MAloyalty" onsubmit="return validateForm(this)" > I am trying to make a simple calculator to calculate dBm, Vpp, Vrms. It is basically a conversion calculator. I am brand new to JavaScript and tried to follow a tutorial but I'm coming up short. I will post both my .js and .html code below. My issue is that when I hit the "Calculate" button nothing happens. Here is the javascript. It has a main calculate function and a function that gives me a log base 10 method. Code: //Main Calculation function calculate() { if(dBm === null && Vpp === null){ var calc = document.getElementById('ecalc'); var Vpp2 = (4*Vrms)/Math.sqrt(2); var dBm2 = 20 * (log10(Vpp/(Math.sqrt(0.008*Z)))); var Vrms2 = Vrms; return false; } else if(Vpp === null && Vrms === null){ var calc = document.getElementById('ecalc'); var Vpp2 = Math.sqrt(0.008*Z)*Math.pow(10,(dBm/20)); var Vrms2 = (Math.sqrt(2)/2)*(Vpp/2); var dBm2 = dBm; return false; } else if(dBm === null && Vrms === null){ var calc = document.getElementById('ecalc'); var dBm2 = 20 * (log10(Vpp/(Math.sqrt(0.008*Z)))); var Vrms2 = (Math.sqrt(2)/2)*(Vpp/2); var Vpp2 = Vpp; return false; } calc.Vpp2.value = Vpp2; calc.Vrms2.value = Vrms2; calc.dBm2.value = dBm2; return false; } //Log base 10 Function function log10(val) { return Math.log(val) / Math.log(10); } Here is the HTML. It has the form in it. As you can see there are 4 inputs. Z is required and only one of the other values can be entered (hence the if statements in the js. 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 content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Untitled 1</title> <script type="text/javascript" src="Calculate.js"> </script> </head> <body> <form id="ecalc" action="#"> <table align="center"border="1"> <tr> <td colspan="2" align="center"> Enter a Z value and one other value. </td> </tr> <tr> <td align="right">dBm: </td> <td align="left"><input type="text" name="dBm" size="20" /></td> </tr> <tr> <td align="right">Vpp: </td> <td align="left"><input type="text" name="Vpp" size="20" /></td> </tr> <tr> <td align="right">Vrms: </td> <td align="left"><input type="text" name="Vrms" size="20" /></td> </tr> <tr> <td align="right">Z (Ohms): </td> <td align="left"><input type="text" name="Z" size="20" value="50" /></td> </tr> <tr> <td colspan="2" align="center"> <input type="button" value="Calculate" onclick= "calculate();" /> </td> </tr> <tr> <td align="right">dBm:</td> <td alig="left"><input type="text" name="dBm2" size="20" readonly="readonly" /></td> </tr> <tr> <td align="right">Vpp:</td> <td alig="left"> <input type="text" name="Vpp2" size="20" readonly="readonly" /></td> </tr> <tr> <td align="right">Vrms:</td> <td alig="left"> <input type="text" name="Vrms2" size="20" readonly="readonly" /></td> </tr> </table> </form> </body> </html> There is probably something simple that needs to be fixed but I have spent a whole day trying to figure this out. If anyone has any comments please let me know. Thanks in advance! It 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> Ok so I know basic html and css, no problem but i just started learning javascript and this class is kicking my but! I have this assignment due tonight and I'm taking this class online so there not much help beyond google. I know it's "simple' but I cannot figure this out for the life of me!!! It driving me bonkers, and I really don't want to fail. So any help would be more that appreciated! K here is the html: <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Change Calculator</title> <link rel="stylesheet" type="text/css" href="default.css" /> <script type="text/javascript" src="calculate_coins.js"></script> </head> <body> <div id="content"> <h1>Change Calculator</h1> <label>Enter number of cents (0-99):</label> <input type="text" id="cents" /> <input type="button" value="Calculate" name="calculate" id="calculate" /><br /> <p> </p> <label>Quarters:</label> <input type="text" id="quarters" class="disabled" disabled="disabled" /><br /> <label>Dimes:</label> <input type="text" id="dimes" class="disabled" disabled="disabled" /><br /> <label>Nickels:</label> <input type="text" id="nickels" class="disabled" disabled="disabled" /><br /> <label>Pennies:</label> <input type="text" id="pennies" class="disabled" disabled="disabled" /><br /> <p> </p> </div> </body> </html> i need to get it to function properly. Please HELLP ME!!! |