Franklin,
for the onkeyup event fire some JavaScript function that checks what key was
pressed (e.g. Tab, which I think is key code = 9) and then take the
appropriate action (e.g. Concat three spaces). Here is a JavaScript function
I have used to identify the key pressed:
function getKeycode(e)
{
var blnDOM = false, blnIE4 = false, blnNN4 = false;
if(document.layers) blnNN4 = true;
else if(document.all) blnIE4 = true;
else if(document.getElementById) blnDOM = true;
if(blnNN4)
{
var NN4key = e.which
return NN4key;
}
if(blnDOM)
{
var blnkey = e.which
return blnkey;
}
if(blnIE4)
{
var IE4key = event.keyCode
return IE4key;
}
}
Here is a function I created in the past that uses the getKeycode:
function formatCurrency(formField, setEmptyToZero, e)
{
//8 = Backspace
//9 = Tab (so will stay highlighted)
//16 = Reverse Tab - Shift+Tab (so will stay highlighted)
//37 = Left Arrow
//39 = Right Arrow
if(getKeycode(e)!= 8)
{
var unformattedCurrency = makeNumeric(formField.value,
setEmptyToZero);
var formattedCurrency = "";
var originalValueLength = formField.value.length;
var decimalIndex = formField.value.indexOf(".");
if(decimalIndex == 0)
{
formattedCurrency = unformattedCurrency;
}
else if(decimalIndex > 0)
{
formattedCurrency = unformattedCurrency.substr(0, decimalIndex)
+ "." + unformattedCurrency.substr(decimalIndex, 2);
}
else
{
formattedCurrency = unformattedCurrency;
}
return formattedCurrency;
}
else
{
return formField.value;
}
}
This is what the text box looks like once rendered, when calling the function:
<input type="text" name="txtTest" id="txtTest"
onkeyup="javascript:this.value=formatCurrency(this, false, event);"
onblur="javascript:this.value=formatCurrency(this, false, event);" />
I hope that helps.