JavaScript - Javascript Problem [currency Convert]?
Similar TutorialsHi 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> 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> 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 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. Any one can help how to convert the below PHP code to javascript code: class Mobile { public static function is_mobile(){ $user_agent = $_SERVER['HTTP_USER_AGENT']; // get the user agent value - this should be cleaned to ensure no nefarious input gets executed $accept = $_SERVER['HTTP_ACCEPT']; // get the content accept value - this should be cleaned to ensure no nefarious input gets executed return false || (preg_match('/ipad/i',$user_agent)) || (preg_match('/ipod/i',$user_agent)||preg_match('/iphone/i',$user_agent)) || (preg_match('/android/i',$user_agent)) || (preg_match('/opera mini/i',$user_agent)) || (preg_match('/blackberry/i',$user_agent)) || (preg_match('/(pre\/|palm os|palm|hiptop|avantgo|plucker|xiino|blazer|elaine)/i',$user_agent)) || (preg_match('/(iris|3g_t|windows ce|opera mobi|windows ce; smartphone;|windows ce; iemobile)/i',$user_agent)) || (preg_match('/(mini 9.5|vx1000|lge |m800|e860|u940|ux840|compal|wireless| mobi|ahong|lg380|lgku|lgu900|lg210|lg47|lg920|lg840|lg370|sam-r|mg50|s55|g83|t66|vx400|mk99|d615|d763|el370|sl900|mp500|samu3|samu4|vx10|xda_|samu5|samu6|samu7|sa mu9|a615|b832|m881|s920|n210|s700|c-810|_h797|mob-x|sk16d|848b|mowser|s580|r800|471x|v120|rim8|c500foma:|160x|x160|480x|x640|t503|w839|i250|sprint|w39 8samr810|m5252|c7100|mt126|x225|s5330|s820|htil-g1|fly v71|s302|-x113|novarra|k610i|-three|8325rc|8352rc|sanyo|vx54|c888|nx250|n120|mtk |c5588|s710|t880|c5005|i;458x|p404i|s210|c5100|teleca|s940|c500|s590|foma|samsu|vx8|vx9|a1000|_mms|m yx|a700|gu1100|bc831|e300|ems100|me701|me702m-three|sd588|s800|8325rc|ac831|mw200|brew |d88|htc\/|htc_touch|355x|m50|km100|d736|p-9521|telco|sl74|ktouch|m4u\/|me702|8325rc|kddi|phone|lg |sonyericsson|samsung|240x|x320|vx10|nokia|sony cmd|motorola|up.browser|up.link|mmp|symbian|smartphone|midp|wap|vodafone|o2|pocket|kindle|mobile|psp |treo)/i',$user_agent)) || ((strpos($accept,'text/vnd.wap.wml')>0)||(strpos($accept,'application/vnd.wap.xhtml+xml')>0)) || (isset($_SERVER['HTTP_X_WAP_PROFILE'])||isset($_SERVER['HTTP_PROFILE'])) || (in_array(strtolower(substr($user_agent,0,4)),array('1207'=>'1207','3gso'=>'3gso','4thp'=>'4thp','50 1i'=>'501i','502i'=>'502i','503i'=>'503i','504i'=>'504i','505i'=>'505i','506i'=>'506i','6310'=>'6310 ','6590'=>'6590','770s'=>'770s','802s'=>'802s','a wa'=>'a wa','acer'=>'acer','acs-'=>'acs-','airn'=>'airn','alav'=>'alav','asus'=>'asus','attw'=>'attw','au-m'=>'au-m','aur '=>'aur ','aus '=>'aus ','abac'=>'abac','acoo'=>'acoo','aiko'=>'aiko','alco'=>'alco','alca'=>'alca','amoi'=>'amoi','anex'=> 'anex','anny'=>'anny','anyw'=>'anyw','aptu'=>'aptu','arch'=>'arch','argo'=>'argo','bell'=>'bell','bi rd'=>'bird','bw-n'=>'bw-n','bw-u'=>'bw-u','beck'=>'beck','benq'=>'benq','bilb'=>'bilb','blac'=>'blac','c55/'=>'c55/','cdm-'=>'cdm-','chtm'=>'chtm','capi'=>'capi','cond'=>'cond','craw'=>'craw','dall'=>'dall','dbte'=>'dbte','dc-s'=>'dc-s','dica'=>'dica','ds-d'=>'ds-d','ds12'=>'ds12','dait'=>'dait','devi'=>'devi','dmob'=>'dmob','doco'=>'doco','dopo'=>'dopo','el49'= >'el49','erk0'=>'erk0','esl8'=>'esl8','ez40'=>'ez40','ez60'=>'ez60','ez70'=>'ez70','ezos'=>'ezos','e zze'=>'ezze','elai'=>'elai','emul'=>'emul','eric'=>'eric','ezwa'=>'ezwa','fake'=>'fake','fly-'=>'fly-','fly_'=>'fly_','g-mo'=>'g-mo','g1 u'=>'g1 u','g560'=>'g560','gf-5'=>'gf-5','grun'=>'grun','gene'=>'gene','go.w'=>'go.w','good'=>'good','grad'=>'grad','hcit'=>'hcit','hd-m'=>'hd-m','hd-p'=>'hd-p','hd-t'=>'hd-t','hei-'=>'hei-','hp i'=>'hp i','hpip'=>'hpip','hs-c'=>'hs-c','htc '=>'htc ','htc-'=>'htc-','htca'=>'htca','htcg'=>'htcg','htcp'=>'htcp','htcs'=>'htcs','htct'=>'htct','htc_'=>'htc_','haie'=> 'haie','hita'=>'hita','huaw'=>'huaw','hutc'=>'hutc','i-20'=>'i-20','i-go'=>'i-go','i-ma'=>'i-ma','i230'=>'i230','iac'=>'iac','iac-'=>'iac-','iac/'=>'iac/','ig01'=>'ig01','im1k'=>'im1k','inno'=>'inno','iris'=>'iris','jata'=>'jata','java'=>'java','kddi'=> 'kddi','kgt'=>'kgt','kgt/'=>'kgt/','kpt '=>'kpt ','kwc-'=>'kwc-','klon'=>'klon','lexi'=>'lexi','lg g'=>'lg g','lg-a'=>'lg-a','lg-b'=>'lg-b','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-f'=>'lg-f','lg-g'=>'lg-g','lg-k'=>'lg-k','lg-l'=>'lg-l','lg-m'=>'lg-m','lg-o'=>'lg-o','lg-p'=>'lg-p','lg-s'=>'lg-s','lg-t'=>'lg-t','lg-u'=>'lg-u','lg-w'=>'lg-w','lg/k'=>'lg/k','lg/l'=>'lg/l','lg/u'=>'lg/u','lg50'=>'lg50','lg54'=>'lg54','lge-'=>'lge-','lge/'=>'lge/','lynx'=>'lynx','leno'=>'leno','m1-w'=>'m1-w','m3ga'=>'m3ga','m50/'=>'m50/','maui'=>'maui','mc01'=>'mc01','mc21'=>'mc21','mcca'=>'mcca','medi'=>'medi','meri'=>'meri','mio8'=> 'mio8','mioa'=>'mioa','mo01'=>'mo01','mo02'=>'mo02','mode'=>'mode','modo'=>'modo','mot '=>'mot ','mot-'=>'mot-','mt50'=>'mt50','mtp1'=>'mtp1','mtv '=>'mtv ','mate'=>'mate','maxo'=>'maxo','merc'=>'merc','mits'=>'mits','mobi'=>'mobi','motv'=>'motv','mozz'=> 'mozz','n100'=>'n100','n101'=>'n101','n102'=>'n102','n202'=>'n202','n203'=>'n203','n300'=>'n300','n3 02'=>'n302','n500'=>'n500','n502'=>'n502','n505'=>'n505','n700'=>'n700','n701'=>'n701','n710'=>'n710 ','nec-'=>'nec-','nem-'=>'nem-','newg'=>'newg','neon'=>'neon','netf'=>'netf','noki'=>'noki','nzph'=>'nzph','o2 x'=>'o2 x','o2-x'=>'o2-x','opwv'=>'opwv','owg1'=>'owg1','opti'=>'opti','oran'=>'oran','p800'=>'p800','pand'=>'pand','pg-1'=>'pg-1','pg-2'=>'pg-2','pg-3'=>'pg-3','pg-6'=>'pg-6','pg-8'=>'pg-8','pg-c'=>'pg-c','pg13'=>'pg13','phil'=>'phil','pn-2'=>'pn-2','pt-g'=>'pt-g','palm'=>'palm','pana'=>'pana','pire'=>'pire','pock'=>'pock','pose'=>'pose','psio'=>'psio','qa-a'=>'qa-a','qc-2'=>'qc-2','qc-3'=>'qc-3','qc-5'=>'qc-5','qc-7'=>'qc-7','qc07'=>'qc07','qc12'=>'qc12','qc21'=>'qc21','qc32'=>'qc32','qc60'=>'qc60','qci-'=>'qci-','qwap'=>'qwap','qtek'=>'qtek','r380'=>'r380','r600'=>'r600','raks'=>'raks','rim9'=>'rim9','rove'=> 'rove','s55/'=>'s55/','sage'=>'sage','sams'=>'sams','sc01'=>'sc01','sch-'=>'sch-','scp-'=>'scp-','sdk/'=>'sdk/','se47'=>'se47','sec-'=>'sec-','sec0'=>'sec0','sec1'=>'sec1','semc'=>'semc','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','sk-0'=>'sk-0','sl45'=>'sl45','slid'=>'slid','smb3'=>'smb3','smt5'=>'smt5','sp01'=>'sp01','sph-'=>'sph-','spv '=>'spv ','spv-'=>'spv-','sy01'=>'sy01','samm'=>'samm','sany'=>'sany','sava'=>'sava','scoo'=>'scoo','send'=>'send','siem'=> 'siem','smar'=>'smar','smit'=>'smit','soft'=>'soft','sony'=>'sony','t-mo'=>'t-mo','t218'=>'t218','t250'=>'t250','t600'=>'t600','t610'=>'t610','t618'=>'t618','tcl-'=>'tcl-','tdg-'=>'tdg-','telm'=>'telm','tim-'=>'tim-','ts70'=>'ts70','tsm-'=>'tsm-','tsm3'=>'tsm3','tsm5'=>'tsm5','tx-9'=>'tx-9','tagt'=>'tagt','talk'=>'talk','teli'=>'teli','topl'=>'topl','hiba'=>'hiba','up.b'=>'up.b','upg1'= >'upg1','utst'=>'utst','v400'=>'v400','v750'=>'v750','veri'=>'veri','vk-v'=>'vk-v','vk40'=>'vk40','vk50'=>'vk50','vk52'=>'vk52','vk53'=>'vk53','vm40'=>'vm40','vx98'=>'vx98','virg'= >'virg','vite'=>'vite','voda'=>'voda','vulc'=>'vulc','w3c '=>'w3c ','w3c-'=>'w3c-','wapj'=>'wapj','wapp'=>'wapp','wapu'=>'wapu','wapm'=>'wapm','wig '=>'wig ','wapi'=>'wapi','wapr'=>'wapr','wapv'=>'wapv','wapy'=>'wapy','wapa'=>'wapa','waps'=>'waps','wapt'=> 'wapt','winc'=>'winc','winw'=>'winw','wonu'=>'wonu','x700'=>'x700','xda2'=>'xda2','xdag'=>'xdag','ya s-'=>'yas-','your'=>'your','zte-'=>'zte-','zeto'=>'zeto','acs-'=>'acs-','alav'=>'alav','alca'=>'alca','amoi'=>'amoi','aste'=>'aste','audi'=>'audi','avan'=>'avan','benq'=> 'benq','bird'=>'bird','blac'=>'blac','blaz'=>'blaz','brew'=>'brew','brvw'=>'brvw','bumb'=>'bumb','cc wa'=>'ccwa','cell'=>'cell','cldc'=>'cldc','cmd-'=>'cmd-','dang'=>'dang','doco'=>'doco','eml2'=>'eml2','eric'=>'eric','fetc'=>'fetc','hipt'=>'hipt','http'=> 'http','ibro'=>'ibro','idea'=>'idea','ikom'=>'ikom','inno'=>'inno','ipaq'=>'ipaq','jbro'=>'jbro','je mu'=>'jemu','java'=>'java','jigs'=>'jigs','kddi'=>'kddi','keji'=>'keji','kyoc'=>'kyoc','kyok'=>'kyok ','leno'=>'leno','lg-c'=>'lg-c','lg-d'=>'lg-d','lg-g'=>'lg-g','lge-'=>'lge-','libw'=>'libw','m-cr'=>'m-cr','maui'=>'maui','maxo'=>'maxo','midp'=>'midp','mits'=>'mits','mmef'=>'mmef','mobi'=>'mobi','mot-'=>'mot-','moto'=>'moto','mwbp'=>'mwbp','mywa'=>'mywa','nec-'=>'nec-','newt'=>'newt','nok6'=>'nok6','noki'=>'noki','o2im'=>'o2im','opwv'=>'opwv','palm'=>'palm','pana'=> 'pana','pant'=>'pant','pdxg'=>'pdxg','phil'=>'phil','play'=>'play','pluc'=>'pluc','port'=>'port','pr ox'=>'prox','qtek'=>'qtek','qwap'=>'qwap','rozo'=>'rozo','sage'=>'sage','sama'=>'sama','sams'=>'sams ','sany'=>'sany','sch-'=>'sch-','sec-'=>'sec-','send'=>'send','seri'=>'seri','sgh-'=>'sgh-','shar'=>'shar','sie-'=>'sie-','siem'=>'siem','smal'=>'smal','smar'=>'smar','sony'=>'sony','sph-'=>'sph-','symb'=>'symb','t-mo'=>'t-mo','teli'=>'teli','tim-'=>'tim-','tosh'=>'tosh','treo'=>'treo','tsm-'=>'tsm-','upg1'=>'upg1','upsi'=>'upsi','vk-v'=>'vk-v','voda'=>'voda','vx52'=>'vx52','vx53'=>'vx53','vx60'=>'vx60','vx61'=>'vx61','vx70'=>'vx70','vx80'= >'vx80','vx81'=>'vx81','vx83'=>'vx83','vx85'=>'vx85','wap-'=>'wap-','wapa'=>'wapa','wapi'=>'wapi','wapp'=>'wapp','wapr'=>'wapr','webc'=>'webc','whit'=>'whit','winw'=> 'winw','wmlb'=>'wmlb','xda-'=>'xda-',))) ; } } hello there.. I'm poor with javascript.. can you help me to convert this php to javascript? Code: <?php setcookie("KNwidget", "fbfans", time()+3600); ?> <?php if (isset($_COOKIE["KNwidget"])) echo "when has COOKIE, nothing show here.."; else echo "<script type='text/javascript'>some java script here</script>"; ?> Hi all, I created a program for my company that allows employees to log in, and make their annual leave selections. It was made in Flash Builder with AS3. It contains a datagrid with 7 available leave slots for each day of the year. Employees click on an available slot and their name in inserted. We go through this process 4 times, with each employee selecting 5 days per round until they have selected up to 20 days of annual leave. We use company seniority to rank the order in which the employees pick. I hope I've explained that clearly enough to have someone help me with my question Since I want to move from Flash, I would like to use Javascript, Jquery and HTML5 to completely redo our website so it can be used on phones, tablets, etc. I have built a calendar and can cycle through the months (i'd eventually like to get a year view), but I'm having issues with a couple of items I had built into the flash version. First of all, I want to be able to show each employees work schedule on the calendar. They all work rotating shifts of 5 on 4 off. In AS3 i've taken their rotation, paired it with a start date for that rotation and was able to indicate in the datagrid "WORKING" on their days of work. This enables them to pick leave on their correct working days. In Jquery, I'd like to color the calendar on the dates that they are scheduled to work. IS that possible? Secondly, they pick 5 days of leave at a time. I'd like to display a token of some sort on the page that contains their name. They could then drag the token to a day that they would like to have off. Once they click submit, the selections are submitted to the MySQL database I have set up. How can I create these tokens based on the user's login name. Sorry for the noob questions. I'm just trying to get my head around the nuances of Javascript and jQuery Thanks for any help!! Hi all, how to convert below vbscript to javascript. Please help me. It is urgent. thanks Function Base64Encode(inData) Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" Dim cOut, sOut, I For I = 1 To Len(inData) Step 3 Dim nGroup, pOut, sGroup nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _ &H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1)) nGroup = Oct(nGroup) nGroup = String(8 - Len(nGroup), "0") & nGroup 'Convert To base64 pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _ Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _ Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _ Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1) 'Add the part To OutPut string sOut = sOut + pOut 'Add a new line For Each 76 chars In dest (76*3/4 = 57) 'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf Next Select Case Len(inData) Mod 3 Case 1: '8 bit final sOut = Left(sOut, Len(sOut) - 2) + "==" Case 2: '16 bit final sOut = Left(sOut, Len(sOut) - 1) + "=" End Select Base64Encode = sOut End Function Function MyASC(OneChar) If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar) End Function Hi, I am trying to convert this excel formula into a Javascript equivalent for a form I am doing in Acrobat Pro 9 and you guessed it. I have no idea. everything is done apart from this. =SUMIF(B2:B29,"LA",A2:A29)+SUMIF(F2:F29,"LA",E2:E2 9) any help very appreciated. cheers Hello. I need help PLEASE ! I need to convert a string Quote: lalaw|lalaw1|lalaw2|lalaw3 in to Array The values I have in variable "tables" I want to create variable list which takes values from "tables" Than I want to split this, and put each value in to new array: I've started with: Code: var list = "tables"; var listArray = list.split("|"); for(i=0; i < listArray.length;i++) { //? how to put now values in to array? } Best Regards Leos 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 ? I am working on a page where the user will select a location from a dynamically generated dropdown list. I was able to create the php multidimensional array (tested and working) from a MySql database using the users information at login, but I'm having problems converting it to a javascript multidimensional array. I need to be able to access variables that I can pass to a number of text fields within an html form. For instance, if a user belongs to a company with multiple addresses, I need to be able to let them select the address they need to prepopulate specific text fields. php array creation: Code: if ($row_locations) { while ($row_locations = mysql_fetch_assoc($locations)) { $mail[$row_locations['comp_id']]=array('mailto'=>$row_locations['mailto'], 'madd'=>$row_locations['madd'], 'madd2'=>$row_locations['madd2'], 'mcity'=>$row_locations['mcity'], 'mstate'=>$row_locations['mstate'], 'mzip'=>$row_locations['mzip'], 'billto'=>$row_locations['billto'], 'badd'=>$row_locations['badd'], 'badd2'=>$row_locations['badd2'], 'bcity'=>$row_locations['bcity'], 'bstate'=>$row_locations['bstate'], 'bzip'=>$row_locations['bzip']); } } javascript function - this should create the array and send variables to text fields. Code: function updateAddress() { var mail = $.parseJSON(<?php print json_encode(json_encode($mail)); ?>); { if (comp_id in mail) { document.getElementById('mailto').value=mail.comp_id.mailto.value; document.getElementById('madd').value=mail.comp_id.madd.value; document.getElementById('madd2').value=mail.comp_id.madd2.value; document.getElementById('mcity').value=mail.comp_id.mcity.value; document.getElementById('mstate').value=mail.comp_id.mstate.value; document.getElementById('mzip').value=mail.comp_id.mzip.value; } else { document.getElementById('mailto').value=''; document.getElementById('madd').value=''; document.getElementById('madd2').value=''; document.getElementById('mcity').value=''; document.getElementById('mstate').value=''; document.getElementById('mzip').value=''; } } } Where is this breaking? Thanks in advance. 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 ... 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 ); 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. 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. 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 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> |