Multi-Line Text Box - How to Insert Spaces

Discussion in 'ASP .Net' started by Franklin, Feb 20, 2009.

  1. Franklin

    Franklin Guest

    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!
     
    Franklin, Feb 20, 2009
    #1
    1. Advertising

  2. 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" wrote:

    > 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!
    >
    >
    >
     
    Luis Ruiz Pavón, Feb 20, 2009
    #2
    1. Advertising

  3. 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.

    --
    William J. Familia


    "Franklin" wrote:

    > 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!
    >
    >
    >
     
    William J. Familia, Feb 20, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kieran Breen

    multi line text box max length

    Kieran Breen, Feb 15, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    10,727
    nataraj_mca
    Jun 14, 2007
  2. Gnarlodious
    Replies:
    4
    Views:
    17,710
    elizas
    May 5, 2010
  3. Replies:
    0
    Views:
    1,084
  4. paul reed

    Limiting size of Multi-line text box

    paul reed, Dec 1, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    159
  5. Replies:
    1
    Views:
    155
    gunnrosebutpeace
    Apr 17, 2008
Loading...

Share This Page