JavaScript - Formating For Currency And Remove Null Values
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 to strip out the values that =0. 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 Similar Tutorials(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 Resolved!
So there is this string i need to parse as xml: Code: <station><code>GB0923A</code><city>ABERDEEN</city><population>215.000</population><component><name>Nitrogen dioxide (air)</name><unit>_micro;g/m3</unit></component><component><name>Nitrogen oxides (air)</name><unit>_micro;g NO2/m3</unit></component></station> Now what I do is: -use this function to create xml doc from string Code: function stringToXML(text){ if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(text,"text/xml"); } else // Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(text); } return xmlDoc; } -display it in that if statement: Code: if (xmlhttp.readyState==4 && xmlhttp.status==200){ var response= xmlhttp.responseText; xmlDoc= stringToXML(response); var text=""; text= text+ xmlDoc.getElementsByTagName("city")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("code")[0].nodeValue + "<br/>"; text= text+ xmlDoc.getElementsByTagName("population")[0].nodeValue + "<br/>"; document.getElementById("test").innerHTML = text; document.getElementById("loading").style.display = "none"; } the stirng shown at the beggining is passed to "response" (var response= xmlhttp.responseText. Now for some reason all 3 values displayed are null... I am trying to figure why for last 2hrs but i cnt see any reason why they shouldnt be the actual values of nodes in the string... Any help would be appreciated. Whenever i try to use this function it gives me either - NaN, or undefined what am i doing wrong? The objective of these functions are to change x and y coordinates into SAN (Simplified Algebraic Notation) for use in the Chess Game's DataFile (PGN file format). Live Running DHTML App: http://daomingjin.googlepages.com/ChessManager.html 140kb Zip-Archive: http://daomingjin.googlepages.com/ScoreMatev1.zip here are the functions in Question: Code: function XCoordToSAN(x) { // Convert the x coordinate of the piece to partial SAN (Simplified Algebraic Notation) for(var xCoord = 0; xCoord > xCoord * 7; xCoord++) { if(x == xCoord * BlockSize) { var SANx = xCoord; } } return SANx; } function YCoordToSAN(y) { var Letters = ["A", "B", "C", "D", "E", "F", "G", "H"]; // Convert the y coordinate of the piece to partial SAN (Simplified Algebraic Notation) for(var yCoord = 0; yCoord > yCoord * 7; yCoord++) { if(y == yCoord * BlockSize) { var SANy = Letters[yCoord]; } } return SANy; } this is how i'm calling the functions: Code: var oldPGNx = XCoordToSAN(oldXposition); var oldPGNy = YCoordToSAN(oldYposition); var newPGNx = XCoordToSAN(newXposition); var newPGNy = YCoordToSAN(newYposition); NewPGNData = oldPGNx + oldPGNy + "-" + newPGNx + newPGNy + " "; // Finally update the Data document.getElementById("PGNArea").value = OldPGNData + NewPGNData; Is there a built in method to remove empty array elements
Hi i have done some reading on the net today because i am getting an error on ie. I did find the javascript twice in my code, once in the header and once here, so i removed it from the header. I also changed to src to the full url. But i am still getting this and i dont know why. the file is located in the root directory. Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; msn OptimizedIE8;ENUS) Timestamp: Sat, 30 Jul 2011 16:03:05 UTC Message: 'null' is null or not an object Line: 8 Char: 3894 Code: 0 URI: http://www.mysite.com/swfobject.js Code: <script type='text/javascript' src='$CONST_LINK_ROOT/swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('player.swf','player','400','300','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv'); s1.write('preview'); </script> <embed src='$CONST_LINK_ROOT/flvplayer.swf?file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv&autoStart=false' width='175' height='175' quality='high' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed> would appreciate any suggestions thanks. i was on 1.5 swfobject i did download 2.2 and im guessing all you do is replace the swfobject.js file to upgrade it, but what happened is it gives me this now. Code: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SearchToolbar 1.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; msn OptimizedIE8;ENUS) Timestamp: Sat, 30 Jul 2011 16:31:08 UTC Message: 'SWFObject' is undefined Line: 1283 Char: 1 Code: 0 URI: http://www.mysite/video_admin.php?type=v i dont mind going back to the old version i just need to get this working and im soooooooo lost lol ok another update, this is becomming maddening lol. once i have this line in the header php Code: <script type='text/javascript' src='$CONST_LINK_ROOT/swfobject.js'></script> I never have to use it again as long as they header php is included correct? This is what is driving me nuts, im back on 1.5 and it says its undefined Code: but am in not defining it on this line? ---> var s1 = new SWFObject('player.swf','player','400','300','9'); <script type='text/javascript' src='swfobject.js'></script> <script type='text/javascript'> var s1 = new SWFObject('player.swf','player','400','300','9'); s1.addParam('allowfullscreen','true'); s1.addParam('allowscriptaccess','always'); s1.addParam('flashvars','file=$CONST_LINK_ROOT/movies/$sql_array->vid_id.flv'); s1.write('preview'); </script> Another Update. I am back to the original question. null is null or not an object.. in my search i have found this found a solution. basically Internet Explorer is crappy and doesnt like the setAttribute property so had to change the onchange handler by directly changing the attrbute for the object like so. object.onchange = function() {} i have no idea what they means, does that mean i need to change swfobject.js or does that mean i have to change my xml request. and if it is the swfobject i have no clue what they mean or what lines Hi I am having trouble with a script. I cannot figure out why I get the message: error: null is null or not an object (In IE8) The site is: www.rayburns.com I have check the javascript for the navigation bar and for the rotating images and cannot see what is missing. Not sure what is not being called. Can someone please help with this. Thank you in advance! Hi I've implemented Busybox on a website to display FLV files in a popup player. This works fine, except for the following error in IE (FF is fine) when I close the popup: 'null' is null or not an object I think I've narrowed it down to the following block of code, but am stuck as to what to do from here. Code: var cl = new Element('img',{ 'styles':{ width:'24px', height:'24px', position:'absolute', top:'-20px', right:'-20px', 'z-index':'100000' }, 'src':'bumpbox/closed.png', 'id':'closer' }) cl.addEvent('click',function(e){ e = new Event(e).stop(); bg.dispose(); $(el).getChildren().dispose(); eff2.start({ 'width':[maxw,1], 'height':[maxh,1], 'left': [endleft,middleH], 'top': [endtop, middleV+s] }) }) The IE error is just giving me line number 1 of the php, but the error, I'm sure, lays in the Javascript. Many thanks 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 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> 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 ); 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 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. 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 |