Javascripts > Javascript Forms > Parse Number to Currency Format
Script Title: Parse Number to Currency Format
Description: This is a handy script for forms that contain money values. It automatically parses the form element of your choice whenever a surfer enters a number into the standard currency format.
Example: Available
Copy the following code into your <HEAD></HEAD> tags.<script> /*Parse number to currency format: By Website Abstraction (www.wsabstract.com) and Java-scripts.net (www.java-scripts.net) */ //Remove the $ sign if you wish the parse number to NOT include it var prefix="$" var wd function parseelement(thisone){ if (thisone.value.charAt(0)=="$") return wd="w" var tempnum=thisone.value for (i=0;i<tempnum.length;i++){ if (tempnum.charAt(i)=="."){ wd="d" break } } if (wd=="w") thisone.value=prefix+tempnum+".00" else{ if (tempnum.charAt(tempnum.length-2)=="."){ thisone.value=prefix+tempnum+"0" } else{ tempnum=Math.round(tempnum*100)/100 thisone.value=prefix+tempnum } } } </script>
Copy the following code between the <BODY></BODY> tags of your html page.<form> <input type="text" size=10 onBlur="parseelement(this)"> </form>
Enter your name and email address to have this script sent right to your Inbox for later viewing. First Name Last Name Email