JavaScript - Help Creating Online Calculator Script
Similar Tutorialshi again, I want to say thank you for all of the help and I have the last assignment that she wants us to do and I had to pull up another assignment that she wanted us to build upon( which is one of those coding without anything advance) Code: <html> <head> <title> COMSC 100 Assignment 10 by Dennis McNeill [1190802] </title> <script> function getInputAsText(_id){return document.getElementById(_id).value} function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)} function setOutput(_id, _value){document.getElementById(_id).value = _value} function calculate() { // declare all variables var variable1 var variable2 var variable3 var variable4 var variable5 // get variable's value = getInputAsNumber() = getInputAsNumber() // perform concatenation // write output value setOutput("resultAsText",resultAsNumber) } </script> </head> <body> Directions:<br> Type 5 numbers and click go<br> The highest of the 5 will appear<br> It is okay to use a decimal point<br> Input values:<br> First<input id="variable1"><br> Second<input id="variable2"><br> Third <input id="variable3"><br> Fourth<input id="variable4"><br> Fifth<input id="variable5"><br> <input type="submit" value="go" onclick="calculate()"> Output<br> Result #1:<input id= "myResult1" size="25"> </body> </html> now she wants us to do max <beta and then name the variables with if a<b and I don't know if I put that in the concatenation or what to name my variables! ugh. NOT ASKING TO DO MY HOMEWORK 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> Hey guys. This should be extremely easy for you to answer. This is actually for an intro to computers class I am taking and I am completely stumped. Basically I have to create a really simple Pythagorean Theorem calculator and this is what I have so far: [CODE] <html> <head> <title>A Pythagoras Conversion</title> </head> <script type="text/javascript"> var right_leg, left_leg, hypotenuse; alert ("This calculates the hypotenuse of a right-angled triangle using the Pytahgorean Thereom. Press <OK> to continue!"); right_leg=prompt("Enter the length of the right leg."); left_leg=prompt("Enter the length of the left leg."); sq1 = right_leg*right_leg; sq2 = left_leg*left_leg; hypotenuse = math.sqrt(sq1 + sq2); alert ("The Hypotenuse= "); </script> <body> </body> </html> [CODE] Everything works except for when it comes to it actually calculating. The calculation window never pops up. Please tell me what I am doing wrong in the calculation here....it is driving me nuts. :/ Thanks so much... I purchased this debt calculator about 6 months ago and thought it was working fine. Turns out that when you enter in 30 for the average interest rate a Warning: Unresponsive Script window pops up and forces you to stop the script. I am very novice to Javascript and tried looking through the code to see if I could find the problem, with no success. I would appreciate it greatly if someone could take a look to see what is wrong. Here is the link to the calculator. http://www.federaldebtreduction.com/calculator.html Thank You. Code: function $(id){ return document.getElementById(id); } var payTotal = 0; var GRAPH_MAX_HEIGHT = 140 function calculate(){ var MINIMUM_PAYMENT_PERCENT = .025; var OUR_FEE_PERCENT = .0; var OUR_FEE_MISC_PERCENT = .64; var loanAmount = $("loanamount").value; var interest = $("interest").value; var clearingDuration = $("monthstopaypoff").value; loanAmount = loanAmount.replace(/\$/g,''); loanAmount = loanAmount.replace(/,/g,''); loanAmount = isNaN(loanAmount)?0:parseInt(loanAmount); var interest = interest.replace(/\%/g,'') / 100; interest = isNaN(interest)?0:interest; var sloan = formatCurrency(loanAmount); // set amount for Total Unsecured Debt updateData('tud_loan', sloan); updateData('cc_loan',sloan); updateData('don_loan', sloan); updateData('our_loan',sloan); var doNothingClearingDuration = monthsToPay(loanAmount,interest,MINIMUM_PAYMENT_PERCENT); updateData('our_dura',clearingDuration); if (loanAmount < 5000){ OUR_FEE_PERCENT = 0.7; } else if (loanAmount < 10000){ OUR_FEE_PERCENT = 0.7; } else if (loanAmount < 20000){ OUR_FEE_PERCENT = 0.69; } else if (loanAmount < 30000){ OUR_FEE_PERCENT = 0.68; } else if (loanAmount < 40000){ OUR_FEE_PERCENT = 0.67; } else if (loanAmount < 50000){ OUR_FEE_PERCENT = 0.66; } else if (loanAmount < 60000){ OUR_FEE_PERCENT = 0.65; } else if (loanAmount < 70000){ OUR_FEE_PERCENT = 0.64; } else if (loanAmount < 80000){ OUR_FEE_PERCENT = 0.63; } else if (loanAmount < 90000){ OUR_FEE_PERCENT = 0.62; } else if (loanAmount < 100000){ OUR_FEE_PERCENT = 0.61; } else { OUR_FEE_PERCENT = 0.60; } var our_fee = loanAmount * OUR_FEE_PERCENT; var our_totcost = (loanAmount * OUR_FEE_MISC_PERCENT) + our_fee; our_totcost = loanAmount*OUR_FEE_PERCENT; var our_TotMonthPay = our_totcost/clearingDuration; var our_monthpay = our_totcost/clearingDuration; // set data for our solution updateData('our_TotalCost',our_totcost, true); updateData('our_monthPay',our_monthpay, true); updateData('our_inter',"None"); updateData('our_exp_inter',"None"); // set data for Consolidated Loan var consLoanIntRate = 0.12; var consLoanMonthPay = (loanAmount * (consLoanIntRate/12))/(1 - Math.pow(1 + (consLoanIntRate/12),-1 * 60)); updateData('tud_monthPay',consLoanMonthPay, true); var consLoanExtraIntPaid = (consLoanMonthPay * 60) - loanAmount; updateData('tud_exp_inter',consLoanExtraIntPaid, true); var consLoanTotCost = (consLoanMonthPay * 60); updateData('tud_TotalCost',consLoanTotCost, true); updateData('tud_inter',(consLoanIntRate * 100) + " %"); updateData('tud_dura',60); // set data if you Do Nothing var doNothingMonthPay = loanAmount*0.03; updateData('don_monthPay',doNothingMonthPay, true); var doNothingExtraIntPaid = payTotal - loanAmount; updateData('don_exp_inter',doNothingExtraIntPaid, true); var doNothingTotalCost = payTotal; updateData('don_TotalCost',doNothingTotalCost, true); updateData('don_dura',doNothingClearingDuration); var don_disp_interest = (interest * 100); updateData('don_inter',don_disp_interest + ' %'); // set data for CreditCounselling var crCounsMonthPay = doNothingMonthPay * 0.95; updateData('cc_monthPay',crCounsMonthPay, true); var crCounsExtraIntPay = (crCounsMonthPay * 60) - loanAmount; updateData('cc_exp_inter',crCounsExtraIntPay, true); var crCounsTotalCost = (crCounsMonthPay * 60); updateData('cc_TotalCost',crCounsTotalCost, true); updateData('cc_inter',"Variable"); updateData('cc_dura',60); displayMonthPay(consLoanMonthPay, crCounsMonthPay, doNothingMonthPay, our_TotMonthPay); displayClearingDuration(60,60,doNothingClearingDuration,clearingDuration); displayTotalCost(consLoanTotCost,crCounsTotalCost,doNothingTotalCost,our_totcost); } function displayGraph(graphID,maxHeight){ if (isNaN(maxHeight)) { maxHeight=0; } var graphObj = $(graphID); var currHeight = graphObj.height if(typeof currHeight.replace != "undefined") currHeight = currHeight.replace(/[p,t,x,\s]/g,'') if(isNaN(currHeight) || currHeight==""){ graphObj.height = 1 setTimeout('displayGraph("' + graphID + '","' + maxHeight + '")',55) } else{ if(parseInt(currHeight) < parseInt(maxHeight)){ graphObj.height = parseInt(currHeight) + 1 setTimeout('displayGraph("' + graphID + '","' + maxHeight + '")',55) } else if(parseInt(currHeight) > parseInt(maxHeight)){ if(parseInt(currHeight) - 1 > 1){ graphObj.height = parseInt(currHeight) - 1 setTimeout('displayGraph("' + graphID + '","' + maxHeight + '")',55) } else graphObj.height = 1 } } } function monthsToPay(baseAmount,yearInt,minPay){ payTotal = 0; var payPerMonth = 0; var remainingDebt = baseAmount; var monthInt = yearInt/12; while(remainingDebt > 0){ var monthPay = remainingDebt * minPay; if(monthPay < 25){ monthPay = 25; } payTotal += monthPay; var intAmount = remainingDebt * monthInt; remainingDebt = remainingDebt - (monthPay - intAmount); payPerMonth++; } return payPerMonth; } function displayMonthPay(conamnt,ccamnt,donamnt,ouramnt){ var maxVal = getMax(conamnt,ccamnt,donamnt,ouramnt); updateData('max_monthly_mark',maxVal, true); updateData('mid_monthly_mark',maxVal/2, true); updateData('min_monthly_mark',0, true); var tud_monp_graph_payperiod = (((conamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var cc_monp_graph_payperiod = (((ccamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var don_monp_graph_payperiod = (((donamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var our_monp_graph_payperiod = (((ouramnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; displayGraph('tud_monp_graph',tud_monp_graph_payperiod); displayGraph('cc_monp_graph',cc_monp_graph_payperiod); displayGraph('don_monp_graph',don_monp_graph_payperiod); displayGraph('our_monp_graph',our_monp_graph_payperiod); } function displayClearingDuration(conamnt,ccamnt,donamnt,ouramnt){ var maxVal = getMax(conamnt,ccamnt,donamnt,ouramnt); updateData('max_months',maxVal); updateData('mid_months',maxVal/2); updateData('min_months',0); var tud_months_graph_time = (((conamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var cc_months_graph_time = (((ccamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var don_months_graph_time = (((donamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var our_months_graph_time = (((ouramnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; displayGraph('tud_months_graph',tud_months_graph_time); displayGraph('cc_months_graph',cc_months_graph_time); displayGraph('don_months_graph',don_months_graph_time); displayGraph('our_months_graph',our_months_graph_time); } function displayTotalCost(conamnt,ccamnt,donamnt,ouramnt){ var maxVal = getMax(conamnt,ccamnt,donamnt,ouramnt); updateData('max_totcost',maxVal, true); updateData('mid_totcost',maxVal/2, true); updateData('min_totcost',0); var tud_tcost_graph_ht = (((conamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var cc_tcost_graph_ht = (((ccamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var don_tcost_graph_ht = (((donamnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; var our_tcost_graph_ht = (((ouramnt/maxVal) * 100) * GRAPH_MAX_HEIGHT) / 100; displayGraph('tud_tcost_graph',tud_tcost_graph_ht); displayGraph('cc_tcost_graph',cc_tcost_graph_ht); displayGraph('don_tcost_graph',don_tcost_graph_ht); displayGraph('our_tcost_graph',our_tcost_graph_ht); } function updateData(id,text, needFormat){ if (needFormat != undefined){ text = formatCurrency(text); } $(id).innerHTML = text; } function getMax(a,b,c,d){ var max = a; if (b>max) max=b; if (c>max) max=c; if (d>max) max=d; return max; } <!-- Begin function formatCurrency(num) { num = num.toString().replace(/\$|\,/g,''); if(isNaN(num)) num = "0"; sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) cents = "0" + cents; for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + '$' + num + '.' + cents); } // End --> I am trying to create a form where you are able to calculate what a total car cost would be based on a 6.25% of the CarAmount. Then I would like to be able to add $125 that with is TitleProcess and then $99 to that which is the LicenseFee. Right now I have not been able to get the tax to work on this code. If someone could get this all to work that would be great, or else even if you program your own code. Thank you so much! <form action="POST" name="myform"> <table border="1" bgcolor="#006666"> <tr> <td align="center" colspan="2"> <script language="JavaScript"><!-- function CarLoanCalculator() { form = document.myform CarAmount= form.CarAmount.value DownPayment= "0" AnnualInterestRate = 625/100 TitleProcess= 125 MonthRate=AnnualInterestRate/12 NumPayments=TitleProcess*12 Prin=CarAmount-DownPayment MonthPayment=Math.floor((CarAmount*AnnualInterestRate)+TitleProcess)) form.NumberOfPayments.value=NumPayments form.MonthlyPayment.value=MonthPayment } // --></script> <font color="#FFFFFF" size="2" face="arial narrow"><b>Car Loan Calculator</b> <br> Enter Your Details & Click the Calculate Button</font></td> </tr> <tr> <td> <table border="0" cellpadding="2"> <tr> <td align="right"><font color="#FFFFFF" size="2" face="arial narrow">Car Loan Amount $ </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="text" size="10" name="CarAmount" value="" onBlur="CarLoanCalculator()" onChange="CarLoanCalculator()"> <br> </font></td> </tr> <tr> <td align="right"><font color="#FFFFFF" size="2" face="arial narrow">Annual Interest Rate </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="text" size="3" name="InterestRate" value="6.25" onBlur="CarLoanCalculator()" onChange="CarLoanCalculator()"> % <br> </font></td> </tr> <tr> <td align="right"><font color="#FFFFFF" size="2" face="arial narrow">Term of Car Loan </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="text" size="3" name="NumberOfTitleProcess" value="125" onBlur="CarLoanCalculator()" onChange="CarLoanCalculator()"> TitleProcess<br> </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="button" name="morgcal" value="Calculate" language="JavaScript" onClick="CarLoanCalculator()"> </font></td> </tr> <tr> <td colspan="3"><font color="#FFFFFF"></font></td> </tr> </table> </td> </tr> <tr> <td> <table border="0" cellpadding="2"> <tr> <td align="right"><font color="#FFFFFF" size="2" face="arial narrow"> Number of Car Payments </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="text" size="7" name="NumberOfPayments"> <br> </font></td> </tr> <tr> <td align="right"><font color="#FFFFFF" size="2" face="arial narrow">Monthly Payment $ </font></td> <td><font color="#FFFFFF" size="2" face="arial narrow"> <input type="text" size="7" name="MonthlyPayment"> <br> </font></td> </tr> <tr> <td align="center" colspan="2"> </td> </tr> </table> </td> </tr> </table> <div align="center"></div> </form> Hi All, Could you please help me in finding a java script for 1031 exchange calculator? Its very urgent and have to complete ASAP. Please help me. Thanks Hi, my name is Joe. I have no expierience in writting scripts buy have managed to put together what I think is a decent website for a local business. It is a local Bait & Tackle shop. I have done this for free as I am retired and work a few days a week in the owners shop. This is my situation. I wish to display the current days high tides in a web page. I have created a database (csv file) which resides on my server This file has two fields: date and tidal times I am looking for a script that test the "date" field and if it is equal to the current date, display the tidal field. Any help would be appreciated. Thanks, I have searched and scoured the web looking for a script like this. I have found different scripts that do certain aspects of what I am looking for, but not ONE that does it all. I am hoping you can help bring my search to an end! I need a script that when a user tries to leave a page, either by typing in a URL in the address bar or clicking an external link they get a Javascript (not pop up window) dialog box asking if they would like to complete a survey. If they click OK they are then redirected to the survey page. If they click cancel it allows them to go on their way to the external link. It needs to be able to decipher between internal and external links. The script needs to work with both IE and FF. This is a must. Safari would be a plus. I would like, BUT IS IN NO WAY A NECESSITY, for the script to also be cookie based in that the user doesn't see it if they've seen it within 7 or 14 days. I really hope you all can help me here as I am lost! If you need any other info from me please let me know! What is best for creating a PTC script
I am trying to create a text area input filed for user input, and i want to be able to allow the user to format thier text, just like the ones used in this user forum. I am writing my website in html, php, javascript and css with a MySql database. I am trying to understand how to create such an format-able text area for input. Any ideas? Thank you; Ice I'm trying to get my Client Side Firefox DHTML app to display a list of eBooks. For this, i have the following files F:\Textbooks.html F:\eBooks.txt F:\FirstBook.txt F:\SecondBook.txt F:\ThirdBook.txt textbooks.html is my DHTML app eBooks.txt is the Library file with a listing of all of my eBooks. Inside of eBooks.txt is the following data: ----------------- FirstBook.txt, SecondBook.txt, ThirdBook.txt, ----------------- FirstBook.txt to ThirdBook.txt are my actual ebooks. The problem that i'm having is that When i try to click on any buttons other than the FirstBook button, i get the following error: ---------------------------------- Error: unterminated string literal Source File: file:///F:/Textbooks.html Line: 1, Column: 10 Source Code: LoadEbook(' ---------------------------------- So, unlike clicking on the FirstBook button, these other buttons do not load the eBook data into the DIV for displaying the eBook data. I use the DOM insepector to checkout the DOM of the button code, and it seems like whitespace maybe is the problem. However, i have removed whitespace from the HTMLdata string, and that's not fixing the problem. did i forget something silly? LOL i'm using FireFox 3.5 to develop this App. So obviously this will not work with anything other than Gecko Based browsers. here is my HTML code: <html> <head> <script language="JavaScript"> var eBookLibrary = "eBooks.txt"; var SystemPath = "f:" + String.fromCharCode(92) function Init() { // Initialize the eBook reader document.getElementById("EbookCanvas").style.visibility = "hidden"; document.getElementById("EbookToolbar").style.visibility = "visible"; document.getElementById("FileManager").style.visibility = "visible"; // Load the List of eBooks in the Library LoadBookList(); } function UpdateEbookList() { // Update the Library of Ebooks alert("Updating eBook Library"); // Go back to the File Manager, and Reload the List of Ebooks LoadBookList(); } function LoadBookList() { // This will load the list of books that are available var EbookList = LoadFromDisk(SystemPath + eBookLibrary); var EbookListArray = EbookList.split(","); for(var x = 0; x < EbookListArray.length -1; x++) { // Strip the Filename Extension off of the eBook File Name // The Name of the Book is always the first Index in the Array var BookName = EbookListArray[x].split("."); // Remove the weird whitespace - it screws things up...i think... BookName[0] = BookName[0].replace(/(^\s*|\s*$)/g, ""); var HTMLdata = HTMLdata + "<input type='button' value='" + "FirstBook" + "'" + " onClick=LoadEbook('" + EbookListArray[x] + "');><br>"; } // For some ****ed up reason the first string always generates an 'undefined' even though it's nonsense // So just delete that from the HTMLdata string, because it's just ugly - LOL HTMLdata = HTMLdata.replace("undefined", ""); HTMLdata = HTMLdata.replace("", " "); // Write the HTML data to the DIV document.getElementById("FileManager").innerHTML = HTMLdata; } function LoadEbook(EbookName) { // Hide the File Manager and Show the Ebook Canvas document.getElementById("FileManager").style.visibility = "hidden"; document.getElementById("EbookCanvas").style.visibility = "visible"; document.getElementById("EbookToolbar").style.visibility = "visible"; // Load the Ebook content into the Ebook Reader Pannel var EbookContent = LoadFromDisk(SystemPath + EbookName); document.getElementById("EbookCanvas").innerHTML = EbookContent; } function LoadFromDisk(filePath) { if(window.Components) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(filePath); if (!file.exists()) return(null); var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream); inputStream.init(file, 0x01, 00004, null); var sInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream); sInputStream.init(inputStream); return(sInputStream.read(sInputStream.available())); } catch(e) { //alert("Exception while attempting to load\n\n" + e); return(false); } return(null); } </script> </head> <body onLoad="Init();"> <div id="FileManager" style="position: absolute; top: 0px; left: 0px; visibility: visible;"> The eBook Library's List of Books will be listed here. Click on one to open it in the eBook Reader </div> <br> <div id="EbookCanvas" style="position: absolute; top: 0px; left: 0px; visibility: hidden;"> </div> <br> <div id="EbookToolbar" style="position: absolute; top: 100px; left: 0px;"> <input type="button" value="Open" OnClick="Init();"> <input type="button" value="Update" OnClick="UpdateEbookList();"> <input type="button" value="Exit" OnClick="MainMenu();"> </div> </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> 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! 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 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 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 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? |