Bekijk de onderstaande video om te zien hoe je onze site als een web app op je startscherm installeert.
Opmerking: Deze functie is mogelijk niet beschikbaar in sommige browsers.
$string=var+',00'
Bedrag: <input type="text" name="bedrag" size="30" onblur="valuta_translate(this)" >
<script type="text/javascript">
// =======================
// Script written by:
// Bo Pennings AKA Wake
// www.bopennings.com
// =======================
function valuta_translate(field)
{
with (field)
{
behind_comma = '' ;// empties the behind comma string
befront_comma = '';// empties the behind dot string
last = -1;
input = field.value; /// puts the inputbox value to the string 'input'
last_commapos=value.lastIndexOf(","); // declares the position of the last comma
last_dotpos=value.lastIndexOf("."); // declares the position of the last dot
if (last_dotpos > last_commapos ) // looks what char (dot or comma) is last in the string and puts the position to string 'last'
{ last = last_dotpos; }
else if (last_commapos > last_dotpos )
{ last = last_commapos;}
if (last >= 0){ // if there is a comma...
behind_comma = input.substring(last + 1 , input.length);} // it puts the chars behind the comma in variable 'behind_comma'
else // if there is no comma or dot.. it sets behind_comma to '0'
{behind_comma = '0';
last = input.length;} // sets last to the input length if there isnt a comma or dot, for returning the complete input
befront_comma = input.substring(0 , last); // declares the chars in front of the comma
if (befront_comma == 0) // looks if a value is set in front of the comma, else it uses '0' to show 0,xx instead of ,xx
{befront_comma = '0';}
//// the chars that are not allowed in the field.. (they will be stripped from the string)
var replacers = new Array('\\.',',','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','!'
,'@','#','\\$','%','\\^','\\&','\\*','\\(','\\)','\\-','\\+','\\{','\\}','\\|','\\:','\\;','\\<','\\>','\\?','\\~','\\`','\\[','\\]');
i = 0;
while(i<replacers.length){ // trims the input from any un-allowed chars
var replacer_value = replacers[i];
var replacer_value = new RegExp(replacer_value, 'gi');
befront_comma = (befront_comma.replace(replacer_value,"")) ;
behind_comma = (behind_comma.replace(replacer_value,""));
i++;
}
function repeat(string, nummer){ // this function is in use for adding zeros behind the comma
oldstring = string;
newstring = "";
i = 0;
for (i = 0; i < nummer; i++)
{newstring = newstring += oldstring;}
return newstring;
};
behind_comma = behind_comma.substring(0 , 2) // declares the first 2 chars for the value behind the comma
if (behind_comma.length < 2){ // this adds zeros to the string behind the comma if it's les then two...
behind_comma += repeat('0',(2 - behind_comma.length));}
while (befront_comma.substring(0,1) == '0' && befront_comma.length > 1) // removes zeros in the first char of the input
{befront_comma = befront_comma.substring(1,befront_comma.length)}
var befront_comma_length = '';
var lastthree = '';
var befront_comma_dotted = '';
while (befront_comma.length > 3){ // adds dots to the string (example: 1023403 change to 1.023.403)
befront_comma_length = befront_comma.length;
lastthree = befront_comma.substring(befront_comma_length, befront_comma_length - 3);
befront_comma = befront_comma.substring(0, befront_comma_length - 3);
lastthree = '.' + lastthree;
befront_comma_dotted = lastthree + befront_comma_dotted;
}
befront_comma = befront_comma + befront_comma_dotted;
field.value = befront_comma + ',' + behind_comma; // puts the new input in the box
}
}
// end of script..
</script>
We gebruiken essentiële cookies om deze site te laten werken, en optionele cookies om de ervaring te verbeteren.