Multi-Line Text Box - How to Insert Spaces

  • Thread starter Thread starter Franklin
  • Start date Start date
F

Franklin

I would like to somehow configure a multi-line textbox so that when the user
presses the Tab key, 3 spaces are entered at the current location of the
cursor (within the text box), rather than causing the next control in the
page to be selected/receive focus. Ideas?

Thanks!
 
Hi Franklin:

Try it to capture JavaScript events ;)

Regards
--
Colabora con el foro: Si la respuesta te es de utilidad marca la pregunta
como respondida.
Luis Ruiz Pavón
ilitia Technologies SRL
MCP - MCTS Web 2.0
Web:
http://luisruizpavon.es
 
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.
 
Back
Top