(Answer) (Category) WebGUI FAQ : (Category) Web Design :
Javascript: Display a number in an input text as money.
 <SCRIPT type="text/javascript" LANGUAGE="JavaScript"><!--
 function outputMoney(number) {
      number=checkval(number);
     return "$"+outputDollars(Math.floor(number-0) + '') + outputCents(number - 0);
 }
function checkval(mycheckval) { mycheckval=mycheckval.replace(/,/g,""); mycheckval=mycheckval.replace(/\$/g,""); return (mycheckval); }
function outputDollars(number) { if (number.length <= 3) return (number == '' ? '0' : number); else { var mod = number.length%3; var output = (mod == 0 ? '' : (number.substring(0,mod))); for (i=0 ; i < Math.floor(number.length/3) ; i++) { if ((mod ==0) && (i ==0)) output+= number.substring(mod+3*i,mod+3*i+3); else output+= ',' + number.substring(mod+3*i,mod+3*i+3); } return (output); } }
function outputCents(amount) { amount = Math.round( ( (amount) - Math.floor(amount) ) *100); return (amount < 10 ? '.0' + amount : '.' + amount); }
//--></SCRIPT>
and for the field, I have...
 <input type="text" name="salary" onclick="this.value=checkval(this.value);this.select();" onBlur="this.value=outputMoney(this.value)"> 
I'm expecting to have JS active for my in-office usage, so I'm not absolutely paranoid about JS being on or off.
I'm also expecting to do something like
 <form onsubmit="salary.value=checkval(salary.value)">
to make certain I've stored the proper type of number.
The onclick part allows for the entire value to be highlighted-selected after removing $ and commas.
Main js code copied from http://www.irt.org/script/723.htm
wg-fomATgwyDOTorg
[Append to This Answer]
Previous: (Answer) Create an RSS feed quickly and easily 6.7+
Next: (Answer) How do I mouse-over thumbnails to replace big image?
This document is: http://www.gwy2.org/cgi-bin/fom?file=108
[Search] [Appearance]
This is a Faq-O-Matic 2.721.
This FAQ administered by ... Gerald Young