JavaScriptBank
04-24-2011, 10:40 PM
Helpful JavaScript for Web development
Auto Thousand-Grouped Number Input Fields
One more JavaScript code example to build an auto thousand-grouped number after the users finish to type. JavaScript source code looks good and very easy to use.... detail (http://www.javascriptbank.com/auto-thousand-grouped-number-input-fields.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)
http://www.javascriptbank.com/javascript.images/form/auto-thousand-grouped-number-input-fields.jpg (http://www.javascriptbank.com/javascript/form/textarea/auto-thousand-grouped-number-input-fields/preview/en/)
Demo: JavaScript Auto Thousand-Grouped Number Input Fields (http://www.javascriptbank.com/auto-thousand-grouped-number-input-fields.html/en/)
How to setup
Step 1: Place JavaScript below in your HEAD section
JavaScript
<script type="text/javascript">
// Created by: Pavel Donchev | http://chameleonbulgaria.com/
// This script downloaded from www.JavaScriptBank.com
function currency(which){
currencyValue = which.value;
currencyValue = currencyValue.replace(",", "");
decimalPos = currencyValue.lastIndexOf(".");
if (decimalPos != -1){
decimalPos = decimalPos + 1;
}
if (decimalPos != -1){
decimal = currencyValue.substring(decimalPos, currencyValue.length);
if (decimal.length > 2){
decimal = decimal.substring(0, 2);
}
if (decimal.length < 2){
while(decimal.length < 2){
decimal += "0";
}
}
}
if (decimalPos != -1){
fullPart = currencyValue.substring(0, decimalPos - 1);
} else {
fullPart = currencyValue;
decimal = "00";
}
newStr = "";
for(i=0; i < fullPart.length; i++){
newStr = fullPart.substring(fullPart.length-i-1, fullPart.length - i) + newStr;
if (((i+1) % 3 == 0) & ((i+1) > 0)){
if ((i+1) < fullPart.length){
newStr = "," + newStr;
}
}
}
which.value = newStr + "." + decimal;
}
function normalize(which){
alert("Normal");
val = which.value;
val = val.replace(",", "");
which.value = val;
}
</script>
Step 2: Copy & Paste HTML code below in your BODY section
HTML
$ <input type="text" name="currencyField1" onchange="currency(this);" />
Javascript floating message (http://www.javascriptbank.com/floating-message-scroller.html) - Javascript multi level drop down menu (http://www.javascriptbank.com/javascript-multi-level-drop-down-menu.html) - JavaScript in_array() (http://www.javascriptbank.com/in-array.html)
The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.
Auto Thousand-Grouped Number Input Fields
One more JavaScript code example to build an auto thousand-grouped number after the users finish to type. JavaScript source code looks good and very easy to use.... detail (http://www.javascriptbank.com/auto-thousand-grouped-number-input-fields.html/en//) at JavaScriptBank.com - 2.000+ free JavaScript codes (http://www.javascriptbank.com/)
http://www.javascriptbank.com/javascript.images/form/auto-thousand-grouped-number-input-fields.jpg (http://www.javascriptbank.com/javascript/form/textarea/auto-thousand-grouped-number-input-fields/preview/en/)
Demo: JavaScript Auto Thousand-Grouped Number Input Fields (http://www.javascriptbank.com/auto-thousand-grouped-number-input-fields.html/en/)
How to setup
Step 1: Place JavaScript below in your HEAD section
JavaScript
<script type="text/javascript">
// Created by: Pavel Donchev | http://chameleonbulgaria.com/
// This script downloaded from www.JavaScriptBank.com
function currency(which){
currencyValue = which.value;
currencyValue = currencyValue.replace(",", "");
decimalPos = currencyValue.lastIndexOf(".");
if (decimalPos != -1){
decimalPos = decimalPos + 1;
}
if (decimalPos != -1){
decimal = currencyValue.substring(decimalPos, currencyValue.length);
if (decimal.length > 2){
decimal = decimal.substring(0, 2);
}
if (decimal.length < 2){
while(decimal.length < 2){
decimal += "0";
}
}
}
if (decimalPos != -1){
fullPart = currencyValue.substring(0, decimalPos - 1);
} else {
fullPart = currencyValue;
decimal = "00";
}
newStr = "";
for(i=0; i < fullPart.length; i++){
newStr = fullPart.substring(fullPart.length-i-1, fullPart.length - i) + newStr;
if (((i+1) % 3 == 0) & ((i+1) > 0)){
if ((i+1) < fullPart.length){
newStr = "," + newStr;
}
}
}
which.value = newStr + "." + decimal;
}
function normalize(which){
alert("Normal");
val = which.value;
val = val.replace(",", "");
which.value = val;
}
</script>
Step 2: Copy & Paste HTML code below in your BODY section
HTML
$ <input type="text" name="currencyField1" onchange="currency(this);" />
Javascript floating message (http://www.javascriptbank.com/floating-message-scroller.html) - Javascript multi level drop down menu (http://www.javascriptbank.com/javascript-multi-level-drop-down-menu.html) - JavaScript in_array() (http://www.javascriptbank.com/in-array.html)
The Site may provide, or third parties may provide, links to non-JavaScriptBank.com Internet World Wide Web sites or resources. Because JavaScriptBank.com has no control over such sites and resources, you acknowledge and agree that JavaScriptBank.com is not responsible for the availability of such external sites or resources, and does not endorse and is not responsible or liable for any content, advertising, products, or other materials on or available from such sites or resources. You further acknowledge and agree that JavaScriptBank.com shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such site or resource.