Comma Converter

If you ever had a business over the web, you might exprienced this problem.  When youy customer enters the price, he/she enters it using the $ symbol or added commas.  However, you don't want these symbols on it because your CGI program can't regonize either $ symbol or commas.  So you need this script now, this script will filter out everything except the numbers and decimal points.  Or it will add cammas to the numbers in case you need it for some reason.




 

Cut and paste the source code of the above script here (Read  How to Cut N Paste for help)

<!-------------Cut------------>
<HTML>
<HEAD>
<SCRIPT>
<!--
function filter(x) {
var num = new Array()
num[0] = "0"
num[1] = "1"
num[2] = "2"
num[3] = "3"
num[4] = "4"
num[5] = "5"
num[6] = "6"
num[7] = "7"
num[8] = "8"
num[9] = "9"
num[10] = "."

if (x == 1) {
        var temp = document.forms[0].inputNum.value
        var temp2 = ""
        for (var i = 0; i < temp.length; i++) {
                for (var j = 0; j < num.length; j++) {
                        if (temp.charAt(i) == num[j]) {
                                temp2 += "" + num[j]
                                }
                        }
                }       
        while (temp2.charAt(0) == "0") temp2 = temp2.substring(1,temp2.length)
        }

else if (x == 2) {
        var temp = document.forms[0].inputNum.value
        var temp2 = ""
        for (var i = 0; i < temp.length; i++) {
                for (var j = 0; j < num.length; j++) {
                        if (temp.charAt(i) == num[j]) {
                                temp2 += "" + num[j]
                                }
                        }
                }       
        while (temp2.charAt(0) == "0") temp2 = temp2.substring(1,temp2.length)
        temp = ""
        if (temp2.indexOf(".") != -1) temp3 = temp2.substring(0,temp2.indexOf("."))
        else temp3 = temp2
        for (var k = temp3.length; k > 0; k=k-3) {
                if (temp3.substring(k-4,k).length == 4) temp = "," + temp3.substring(k-3,k) + temp
                else temp = temp3.substring(k-3,k) + temp
                }
        temp2 = temp
        }

document.forms[0].inputNum.value = temp2
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT NAME="inputNum" SIZE=16><BR>
<INPUT TYPE=button VALUE="Filter out all characters but numbers" onClick="filter(1)"><BR>
<INPUT TYPE=button VALUE="Filter out non number characters and insert cammas" onClick="filter(2)">
</BODY>
</HTML>
<!------------End------------->
IMPORTANT: The scripts provided in this page are free as long as you keep the credits in the code.  E-mail me or use Script Rebuild Service for additional help about Cut N Paste or to ask for a script that is just for you.
 
Post Your Script Home