JavaScript - Currency Calculator Problem
Hey I've been working on my Spanish Clubs' website over the summer and I need some help when making this converter. I want to make it so when someone chooses a different country, it will change the answeres and do the equation in the text boxes and also if they change the numbers manually they will also do the equation.
I've tried it out and it's making me go mad. PLEASE HELP! Here is the javascript code I made: Code: function calculatecountry() { var country = calculate.countrys.options[calculate.countrys.selectedIndex].text; //===============================COUNTRIES==================================== if (countrys=="--Country--") { var usd1 = 0; var other1 = 0; } if (countrys=="Argentina") { var usd1 = 0.2553; var other1 = 1; } if (countrys=="Bolivia") { var usd1 = 0.14245; var other1 = 1; } if (countrys=="Chile") { var usd1 = 0.0018; var other1 = 1; } //================================EQUATIONS===================================== var c1 = calculate.other.value; var c2 = calculate.usd.value; var ans1 = c1 * other1; var ans2 = c2 * usd1; calculate.usd.value = ans1; calculate.other.value = ans2; } Here is the form code: Code: <html><head><title></title> <script type="text/javascript" src="js_money_calc.js"></script> </head><body> Converter <form name="calculate"> <select name="countrys" onChange="calculatecountry()"> <option selected>--Country--</option> <option>Argentina</option> <option>Bolivia</option> <option>Chile</option> </select><p> <input type="text" name="usd" onKeyUp="calculatecountry()" /> = <input type="text" name="other" onKeyUp="calculatecountry()" /></p> </form> </body></html> Thanks. Similar TutorialsHi, 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> I have this project i have to complete for class, that i cant figure out. this is what the project says: Prompt the user for the grades of 10 students with one prompt for each grade with the prompting text being: "Enter grade between 1 and 10 for student n:" where n varies from 1 to 10. If the grade input is not between 1 and 10, please prompt again for the grade. Once the user is done, it prints a report telling you the grade of each individual student and the average of the ten grades. The individual student grade should be in different lines with the text "Grade for student n is x". The average should also be in a different line with the text "Average grade is y". The average grade should not be rounded off. my problem is i cant figure out how to write each individual grade (from 1 through 10), and display it on the page. i have this code from a similar project, i tried to ammend it for this code but i always end up ruining it any tips on how to display each grade (1-10)? or how to verify that the user only enters grades between 1 and 10 Code: <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Class Average Program: Sentinel-controlled Repetition</title> <script type = "text/javascript"> <!-- var total; // sum of grades var gradeCounter; // number of grades entered var grade; // grade typed by user (as a string) var gradeValue; // grade value (converted to integer) var average; // average of all grades // Initialization phase total = 0; // clear total gradeCounter = 0; // prepare to loop // Processing phase // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); while ( gradeValue != -1 ) { // add gradeValue to total total = total + gradeValue; // add 1 to gradeCounter gradeCounter = gradeCounter + 1; // prompt for input and read grade from user grade = window.prompt( "Enter Integer Grade, -1 to Quit:", "0" ); // convert grade from a String to an integer gradeValue = parseInt( grade ); } // end while // Termination phase if ( gradeCounter != 0 ) { average = total / gradeCounter; // display average of exam grades document.writeln( "<h1>Class average is " + average + "</h1>" ); } // end if else document.writeln( "<p>No grades were entered</p>" ); // --> </script> </head> <body> <p>Click Refresh (or Reload) to run the script again</p> </body> </html> hi guys, im haveing a bit of a problem with this script - its a ratio calculator. can you guys see whats the problem? Heres the java script eg. when you write 86708 kills and 53240 death the K/D calc should show this: 1,62 = 86 (-86) 1,64 = 389 1,70 = 3582 but it doesent???? heres the code guys : <HTML> <HEAD> <script type="text/javascript"> function find_ratio() { var x = document.getElementById("x1").value; var y = document.getElementById("y1").value; var gcd=calc(x,y); var r1=x/gcd; var r2=y/gcd; var ratio = r1 / r2; document.getElementById("res").value = ratio.toFixed(2); var death1 = r1 / r2; death1 = Math.floor(ratio * 100) / 100; document.getElementById("death1").value = death1.toFixed(2); var kill1 = r1 / r2; kill1 = Math.ceil(ratio * 100) / 100; document.getElementById("kill1").value = kill1.toFixed(2); var kill3 = r1 / r2; kill3 = Math.ceil(ratio * 10) / 10; document.getElementById("kill3").value = kill3.toFixed(2); var deathcalc = (death1 - 0.00401) * r2; var death2 = deathcalc - r1; document.getElementById("death2").value = death2.toFixed(0); var killcalc1 = (kill1 - 0.00401) * r2; var kill2 = killcalc1 - r1; document.getElementById("kill2").value = kill2.toFixed(0); var killcalc2 = (kill3 - 0.00401) * r2; var kill4 = killcalc2 - r1; document.getElementById("kill4").value = kill4.toFixed(0); } function calc(n1,n2) { var num1,num2; if(n1 < n2){ num1=n1; num2=n2; } else{ num1=n2; num2=n1; } var remain=num2%num1; while(remain>0){ num2=num1; num1=remain; remain=num2%num1; } return num1; } function isInteger(s,iid) { var i; s = s.toString(); for (i = 0; i < s.length; i++) { var c; if(s.charAt(i)==".") { } else { c = s.charAt(i); } if (isNaN(c)) { alert("Given value is not a number"); document.getElementById(iid).value=""; return false; } } return true; } </script> <style type="text/css"> .style1 { width: 90px; } .style2 { height: 55px; } #x1 { text-align: center; } #y1 { text-align: center; } </style> </HEAD> <BODY> <table cellspacing=0 cellpadding=2 style="border:1px solid green; width: 250px; height: 217px;" align=center> <tr><td class="style1">Kills:</td><td style="text-align: center"><input type="text" id="x1" onkeyup="isInteger(this.value,this.id);"></td></tr> <tr><td class="style1">Death:</td><td style="text-align: center"><input type="text" id="y1" onkeyup="isInteger(this.value,this.id);"></td></tr> <tr><td colspan=2 align=center class="style2"><input type="button" value="Lad magien flyde" onclick="find_ratio()"></td></tr> <tr><td class="style1">Ratio:</td><td style="text-align: center"><input type="text" readonly id="res" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="res2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Deaths to:</td><td style="text-align: center"> <input type="text" readonly id="death1" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="death2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Kills to:</td><td style="text-align: center"> <input type="text" readonly id="kill1" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="kill2" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr> <tr><td class="style1">Kills to:</td><td style="text-align: center"> <input type="text" readonly id="kill3" style="font-weight:bold; width: 65px; text-align: center;" size="6"> = <input type="text" readonly id="kill4" style="font-weight:bold; width: 65px; text-align: center;" size="6"></td></tr></table> </BODY> </HTML> I am a student trying to complete this assignment. Any assistance you can give me is greatly appreciated. My code is inserted below. This is calculator program that I have gotten stuck on. Here is where I think I am at: The program is now taking the 1st number entered displaying it and storing it in the variable "memory". Operation (+,-,*,/) is added to the memory in function action1() but then when the second number is entered it replaces memory with the second number. How can I get the variable memory to the whole string of 1st number,action, 2nd number? Also once I do get that working correctly: Wouldn't eval(document.calculator.display.value= memory) in my HTML for the "=" give me the calculation. ( if I could figure out how to have memory store the 1st number and action1 and 2nd number all together) Or would eval(document.calculator.display.value) do it for me. //////////////////////////////////////////////////////////////////////////////////// <html> <head> <title> Calculator</title> </head> <script type = "text/javascript" src="calculator2.js"></script> <body> <center>Calculator<br> To use this calculator, CLICK a number, then an ACTION, then another number, then the EQUALS button. <br> Press "C" when ready to start over. <br> The "N" button makes your previous number a negative.<br></center> <form name="calculator"> <table border = "1" align ="center"> <tr> <td ><input type = "text" size = 26 name = "display" id = ""/></td> </tr> <tr ><br /> <!-- first row of calculator --> <td> <input type = "button" value = " 7 " id = "" onclick="newstring('7')"> <input type = "button" value = " 8 " id = "" onclick="newstring('8')"/> <input type = "button" value = " 9 " id = "" onclick="newstring('9')"> <input type = "button" value = " / " id = "" onclick="action1('/')"> </td> </tr> <tr ><br /> <!-- second row of calculator --> <td> <input type = "button" value = " 4 " id = "" onclick="newstring('4')"> <input type = "button" value = " 5 " id = "" onclick="newstring('5')"> <input type = "button" value = " 6 " id = "" onclick="newstring('6')"> <input type = "button" value = " * " id = "" onclick="action1('*')"> </td> </tr> <tr ><br /> <!-- third row of calculator --> <td> <input type = "button" value = " 1 " id = "" onclick="newstring('1')"> <input type = "button" value = " 2 " id = "" onclick="newstring('2')"> <input type = "button" value = " 3 " id = "" onclick="newstring('3')"> <input type = "button" value = " - " id = "" onclick="action1('-')"> </td> </tr> <tr ><br /> <!-- forth row of calculator --> <td> <input type = "button" value = " 0 " id = "" onclick="newstring('0')"> <input type = "button" value = " N " id = "" onclick="newstring('N')"> <input type = "button" value = " = " id = "" onclick="eval(document.calculator.display.value= memory)"> <input type = "button" value = " + " id = "" onclick="action1('+')"> </td> </tr> <tr ><br /> <!-- fifth row of calculator --> <td> <input type = "button" value = "   " id = ""> <input type = "button" value = "   " id = ""> <input type = "button" value = "   " id = ""> <input type = "button" value = " C " id = "" onclick="clearCalc()"> </td> </tr> </table> </body> </form> </html> /////////////////////////////////////////////////////////////////////////////////////// javascript memory = "0"; current = 0; operation =0; function newstring(digit) { current=document.calculator.display.value; if (digit >= 0 && digit <=9) { if(current==0) { current = digit; } else { current = current + digit; } } document.calculator.display.value=current; memory= current; } function action1(newaction) { operation = document.calculator.display.value; if (newaction == '+') { operation = newaction; } else if (newaction == '-') { operation = newaction; } else if (newaction == '*') { operation = newaction; } else if (newaction == '/') { operation = newaction; } memory= memory + operation; document.calculator.display.value=memory ; } function clearCalc() { document.calculator.display.value=null; num1= null; num2 = null; lastaction= null; action = null; } Hello I have this script Code: /* This script and many more are available free online at The JavaScript Source!! http://javascript.internet.com Created by: Mario Costa | */ function currencyFormat(fld, milSep, decSep, e) { var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; if (whichCode == 13) return true; // Enter if (whichCode == 8) return true; // Delete key = String.fromCharCode(whichCode); // Get key value from key code if (strCheck.indexOf(key) == -1) return false; // Not a valid key len = fld.value.length; for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; aux = ''; for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); aux += key; len = aux.length; if (len == 0) fld.value = ''; if (len == 1) fld.value = '0'+ decSep + '0' + aux; if (len == 2) fld.value = '0'+ decSep + aux; if (len > 2) { aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--) { if (j == 3) { aux2 += milSep; j = 0; } aux2 += aux.charAt(i); j++; } fld.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) fld.value += aux2.charAt(i); fld.value += decSep + aux.substr(len - 2, len); } return false; } and I call it like that: onKeyPress="return(currencyFormat(this,',',',',event))" the ouput is: 100,000.00 How can I get rid of of the last 2 ziros after the last dot I need this kind of output 1,000 10,000 100,000 1,000,000 any help ? Hi I have the following currency converter code which works fine, but I need to make it possible for someone else to edit the euro price using a visual editor such as contribute. 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> <script language='javascript'> exchRate = 1.13; function getUKP(price) { document.write('(£' + Math.round(price / exchRate) + ')'); } </script> </head> <body> <strong>€526</strong> <script type="text/javascript">getUKP('526');</script><br /><br /> <strong>€1999</strong> <script type="text/javascript">getUKP('1999');</script> </body> </html> This code requires someone to change the figure in the javascript as well as the html. I guess I need to somehow automatically pick up the numeric characters only from the html which appear on the same line of code... or perhaps there's an easier way.? Any help would be much appreciated. Thanks We format euro currency as 1.000.000,00 (just the opposite of USD). Anyone who could give me a script that changes the input into this format? I tried 'replace' with a regular expression, but my regexes don't work. ... or at least adding the commas? I need to format this number as currency. It is within the "flot" code, which is a charting framwork. I dont know anything about javascript at all so bear with me. Here is part of the code, the piece in red calls for the number. This is what I need displayed with commas, so its easy to read. I have found a few examples on the web but I have no idea how to apply them to this code. Can anyone help? Code: var previousPoint = null; $("#placeholder").bind("plothover", function (event, pos, item) { $("#x").text(pos.x.toFixed(2)); $("#y").text(pos.y.toFixed(2)); if ($("#enableTooltip:checked").length > 0) { if (item) { if (previousPoint != item.datapoint) { previousPoint = item.datapoint; $("#tooltip").remove(); var x = item.datapoint[0].toFixed(2), y = item.datapoint[1].toFixed(2); showTooltip(item.pageX, item.pageY, '<b>' + item.series.label + '</b> '+ ": " + y ); Dear All, On my HTML page, I am trying to use as a snippet the script for automatic currency conversion. It is well known that exchange rates between currency are being changed very often (most of times even daily) and I don't want to republish either page with script or entire website every time the exchange rate changes. For website design I am using xsitepro software because I don't know programming. So what I would like to have on specific page of website is something similar to table (if anyone has any better recommendation than using a table, please share). In this table I would like to state prices of my services. Primary currency is only one. So in this column, the numbers shouldn't be changed unless I want to change the prices (and of course therefore republish the website, no need to republish sitemap). In the rest of the columns the numbers should be changed immediately, without needing to republish anything (thats the point of the script) and also rounded to each 5. What I mean with ''each 5'' is shown on few of the following random chosen examples (1500): 1500.03 is rounded to 1500 1500.30 is rounded to 1500 1500.50 is rounded to 1500 1502.49 is rounded to 1500 1502.50 is rounded to 1505 (!) 1504.99 is rounded to 1505 1505.01 is rounded to 1505 1507.49 is rounded to 1505 1507.50 is rounded to 1510 and so on. Idea is to prevent from getting coins. So the break point is on 2.50, 7.50, 12.50, 17.50, 22.50, 27.50 and so on. Not sure how to mathematically describe this. Hopefully I was understandable. I want to have in the columns only the currencies that I am willing to accept if potential client cannot change the currency to my primary one (given in second most left column) in his local exchange office. But I repeat that what Im trying to do is having automatically and immediately updated numerical values on particular HTML page based on most recent exchange rates (of course trustful source is needed). Since I don't know programming, I did some research on google and discovered this: http://coinmill.com/webmaster_options.html The downer script on the right side looks ok but its not even close to what I need due to five reasons: - it is being converted outside the table - with such way i cannot clearly show which currency is primary (prefered) one - conversion is being done to only one other currency at the same time - no rounding to ''each 5'' - unknown source (and therefore untrustful one) of updating most recent exchange rates Table such as this one: http://www.x-rates.com/ looks great but still not meeting my requirements. I would like to replace flags in the left column with ''service 1'', ''service 2'', ''product 1'' etc. Also I have no idea how rounding could be done. So at the end I would end up with something like (here Im showing only two ''still willing to accept'' currencies just to show an example): Currency:Euro Currency:American Dollar Currency:Japanese Yen Service1 500 670 51535 Service2 400 535 41228 Service3 200 265 20614 Top left corner as it is on x-rates.com would be even better. note: when I previewed my post before submitting, I noticed that the forum doesn't let me make so much spaces but I think those numbers are still understandable where do they belong. Any help would be muuuuuch appricated Hi, I'm really stupid and haven't been working with javascript long, so forgive my incompetence. I need to create a simple currency convertor. Not with live rates or anything like that. It needs to allow a user to input a dollar amount, add a bank fee to that and convert the amount into one of six currencies. here is my code Code: <html> <head> <script type="text/javascript"> <!-- var Amount=document.getElementById('amount'); var Fees=document.getElementById('bankComm'); var Total=document.getElementById('ausTotal'); var Currency=document.getElementById('currency'); var Converted=document.getElementById('converted'); var Choice=document.getElementById('choice'); function fees() { var Amount=document.getElementById('amount'); var Fees=document.getElementById('bankComm'); if (Amount.value>=1&&Amount.value<5001) { Fees.value=20 } if (Amount.value>=5001&&Amount.value<10001) { Fees.value=30 } if (Amount.value>=10001) { Fees.value=40 } } function addFees() { var Amount=document.getElementById('amount'); var Fees=document.getElementById('bankComm'); var Total=document.getElementById('ausTotal'); Total.value=Fees.value+Amount.value } function convert() { var Amount=document.getElementById('amount'); var Currency=document.getElementById('currency'); var Converted=document.getElementById('converted'); var Choice=document.getElementById('choice'); var US=0.91810; var UK=0.60285; var HK=7.12812; var SNG=1.26784; var JY=84.2563; var NZ=1.29565; switch(document.convertor.currency.value) { case:"US Dollars" document.convertor.converted.value=US*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break case:"UK Ponds" document.convertor.converted.value=UK*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break case:"HK Dollars" document.convertor.converted.value=HK*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break case:"Singapore Dollars" document.convertor.converted.value=SNG*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break case:"Japanese Yen" document.convertor.converted.value=JY*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break case:"NZ Dollars" document.convertor.converted.value=NZ*document.convertor.amount.value document.convertor.choice.value=document.convertor.currency.value break } } //--> </script> </head> <body> <div id="divWrapper"> <form name="Convertor" id="Convertor"> Enter amount in Australian Dollars $ <input name="amount"type="text" id="amount" onBlur="fees()" value="0" size="7" /> + $<input name="bankComm" type="text" id="bankComm" style="border:0px" onChange="addFees()" value="0" size="2" /> administration charges = <input name="ausTotal" type="text" id="ausTotal" style="border:0px" value="0" size="7"> <br /><br /> Please select a currency <select name="currency" id="currency"> <option>Please Choose One</option> <option value="US Dollars">US Dollars</option> <option value="UK Pounds">UK Pounds</option> <option value="HK Dollars">HK Dollars</option> <option value="Singapore Dollars">Singapore Dollars</option> <option value="Japanese Yen">Japanese Yen</option> <option value="NZ Dollars">NZ Dollars</option> </select><br /><br /> The amount is: <input name="converted" type="text" id="converted" value="" size="7"/> in <input name="choice" type="text" id="choice" style="border:0px" value=""> <br /><br /> <input name="convert" type="button" id="convert" onClick="convert()" value="Convert" /> </form> </div> </body> </html> I've tried using getElementbyId and using the names, as far as I can tell, it's sytactically correct, but It doesn't seem to work no matter what I do. I have a headache, actually I have two. If anyone can help me, I'd be extremely grateful. Hey guys. I am in an introductory computer science class and I am having trouble writing JavaScript code for a currency converter. I can get it to where it spits out numbers, but its always the same numbers. I think there's something wrong in the calculations part of my code but I can't figure it out. I am posting it below, and any help would be greatly appreciated. Thank you. <html> <head> <title>CURRENCY CONVERTER</title> <script language="JavaScript"> function converting() { with (document.conversions) { if (unit[1].selected) { var result = eval(unit.value*0.974); convertedValue.value = result; } // end if if (unit[2].selected) { var result = eval(unit[2].value*0.492); convertedValue.value = result; } // end if if (unit[3].selected) { var result = eval(unit[3].value*0.706); convertedValue.value = result; } // end if } // end with } // end function converting </script> </head> <form name = "conversions"> <table border=6 bgcolor ="yellow"> <tr> <td><font color="red" size=6>Enter amount in U.S. $:</font></td> <td><input type="text" name="inUnit" size = 4></td> </tr> <tr> <td><font color="red" size=6>Select target unit:</font> <td><select name="unit"> <option value="Select Currency" selected>Choose one... <option value="1">Canadian Dollars <option value="2">British Pounds <option value="3">Euros </select> <td><input type="button" value="Convert" onclick="converting()"> </tr> <tr> <td><font color="green" size=6>Converted Value:</font> <td><input type="text" name="convertedValue" size = 4> <td><input type="reset" value="Reset"> </tr> </table> </form> </body> </html> Hi, I need to create a currency converter using a drop down menu. Firstly i needed to do a regular expressions check to make sure only numerics are entered and I got that. The one thing im pretty confused on is how to do the calculations in the actual function. Ive popped the code below, and if anyone could give me some hints on how to get the data from the drop down menu and calculate it properly that would be awesome. Thanks. -oh and i know all my coding is here but i think its relevent that you can view it all. Code: <html> <head> <style type ="text/css"> @import url(style.css); </style> <script type="text/javascript"> function convert() { var OK = true; var inDollar= document.getElementById('dollars').value; var regex= /^\d{1,}$/; if (!regex.test(inDollar)) { OK=false; alert('Australian Dollars must be entered as numeric with no decimal places'); } return OK; var rate= country.conversion.value; if (document.getElementByID('conversion').selectedIndex == 0) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' US Dollars'); } if (document.getElementByID('conversion').selectedIndex == 1) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Euro'); } if (document.getElementByID('conversion').selectedIndex == 2) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Yuan'); } if (document.getElementByID('conversion').selectedIndex == 3) { var rate= country.conversion.value; var convert = inDollar*rate; alert('$'+inDollar+' converts to'+rate+' Yen'); } } </script> </head> <body> <h1>Currency Page</h1> <form> Australian Dollars:<input type="text" name="dollars" id="dollars" /> <br /> Convert to: <select id='conversion' name='country'> <option value=".73">US Dollars</option> <option value=".62">Euro</option> <option value="5.8">Chinese Yuan</option> <option value="78.5">Japanese Yen</option> </select> <br /> <input type="button" value="Convert" onClick="convert()" /> </form> </body> </html> I can only seem to find really complicated ones online, nothing simple which i think this is. Thanks Hi all, Im in the process of creating a auction site for charity, im working on the last page which allows the user to enter a bid i have this javascript function that i have been working on to try and achieve the following. the user enters a bid use javascript to check to make sure its greater then and not equal to the current price simple right? But no its not well as im new to this maybe iv got lost in the code some where heres my code Code: function IsNewBidGreater(windowname) { var NewBid; var CurrentPrice; CurrentPrice = document.getElementById('MainContent_txtCurrentPrice').value; NewBid = document.getElementById('MainContent_txtNewBid').value; parseFloat(NewBid).toFixed(2); parseFloat(CurrentPrice).toFixed(2); if (NewBid < CurrentPrice || NewBid == CurrentPrice) { NewBid.className = "error"; document.getElementById('MainContent_ErrorLowBid').style.display = 'block'; return false; } else { document.getElementById('MainContent_ErrorLowBid').style.display = 'none'; document.getElementById('MainContent_BidConfirm').innerHTML = NewBid; ConPopUp(windowname) } } where i enter 10.50 and the current price is 9.99 i get the error message saying needs to be greater MainContent_ErrorLowBid is a hidden div on the web page which shows an error message any help would be highly appreciated this code is formatting the price like that 500 000 but i need to price format like this 500.000 so i need dot instead space code at below PHP Code: <html> <head> <script type="text/javascript"> window.onload = attachEvents; function attachEvents() { document.getElementById('myInput').onkeyup = reformatNumber; } function reformatNumber() { // No error checking. Assumes only ever 1 DP per number var text = this.value; // Strip off anything to the right of the DP var rightOfDp = ''; var dpPos = text.indexOf('.'); if (dpPos != -1) { rightOfDp = text.substr(dpPos); text = text.substr(0, dpPos); } var leftOfDp = ''; var counter = 0; // Format the remainder into 3 char blocks, starting from the right for (var loop=text.length-1; loop>-1; loop--) { var char = text.charAt(loop); // Ignore existing spaces if (char == ' ') continue; leftOfDp = char + leftOfDp; counter++; if (counter % 3 == 0) leftOfDp = ' ' + leftOfDp; } // Strip leading space if present if (leftOfDp.charAt(0) == ' ') leftOfDp = leftOfDp.substr(1); this.value = leftOfDp + rightOfDp; } </script> </head> <body> <form> <input type="text" id="myInput" /> </form> </body> </html> Hi Guys, I'm looking for a way to convert a number in to currency format so 10000000 is 10,000,000 etc... i found this code and was hoping someone could advise how to tweak it so that it works automatically without having to hit a button i.e. I will be passing a value dynamically to the code and want it evaluated without the user clicking anything if the code was like var="10000000" <-the number I dynamically pass in and output 10,000,000 You probably guessed Javascript aint my forte. Thanks http://www.designerwiz.com/JavaScrip...ncy_format.htm Code: <!-- // == This Script Free To Use Providing This Notice Remains == // // == This Script Has Been Found In The http://www.DesignerWiz.com Javascript Public Archive Library == // // == NOTICE: Though This Material May Have Been In A Public Depository, Certain Author Copyright Restrictions May Apply == // --><script language="JavaScript" type="text/javascript"> <!-- Begin function checkNum(data) { // checks if all characters var valid = "0123456789."; // are valid numbers or a "." var ok = 1; var checktemp; for (var i=0; i<data.length; i++) { checktemp = "" + data.substring(i, i+1); if (valid.indexOf(checktemp) == "-1") return 0; } return 1; } function dollarAmount(form, field) { // idea by David Turley Num = "" + eval("document." + form + "." + field + ".value"); dec = Num.indexOf("."); end = ((dec > -1) ? "" + Num.substring(dec,Num.length) : ".00"); Num = "" + parseInt(Num); var temp1 = ""; var temp2 = ""; if (checkNum(Num) == 0) { alert("This does not appear to be a valid number. Please try again."); } else { if (end.length == 2) end += "0"; if (end.length == 1) end += "00"; if (end == "") end += ".00"; var count = 0; for (var k = Num.length-1; k >= 0; k--) { var oneChar = Num.charAt(k); if (count == 3) { temp1 += ","; temp1 += oneChar; count = 1; continue; } else { temp1 += oneChar; count ++; } } for (var k = temp1.length-1; k >= 0; k--) { var oneChar = temp1.charAt(k); temp2 += oneChar; } temp2 = "$" + temp2 + end; eval("document." + form + "." + field + ".value = '" + temp2 + "';"); } } // End --></script> <center> <form name=commaform>Enter a number then click the button: <input type=text name=input size=10 value=""> <input type=button value="Convert" onclick="dollarAmount(this.form.name, 'input')"> <br><br> or enter a number and click another field: <input type=text name=input2 size=10 value="" onBlur="dollarAmount(this.form.name, this.name)"> </form> (previously posted in the wrong forum and re-posted in this one) Hi there, I have scoured the internet looking for the right code but to no avail. I have gotten as far as totaling up my form but now want to format the amounts and total as currency and also want the values that = 0 to just be blank. I have tried to use the code from other solutions (posted on the net) but I just think it is over my head because I cant figure it out. I thought I was close a few times but wasn't able to bring it on home. One of my issues is using somebody's code and not knowing where in my code to place it. http://www.whackyweedremoval.com/wwr-invoice.html I have tried exhaustively to solve on my own but there is a point. Please help Anyone ever did this before? domain1.com will have a paragraph of one currency price domain2.com will have the same paragraph with a different currency price. Hello, Firstly - relatively new to javascript. I have seen many examples of code that will return a passed value in a currency format - however I have a sales form that is calculating values via a function in the text boxes I want formatted with a currency ($) symbol. The function that is called is not passing any values, and returning a calculation of the form subtotals per item, and then total sales figure. Can anybody give me any hints on format these cells to a currency value? I can give examples of how my code is currently if required. Thanks in advance |