Tab keycode

Discussion in 'Javascript' started by pra__, Jul 14, 2008.

  1. pra__

    pra__ Guest

    Hi,
    I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
    when a 'tab' key is pressed. I have this code, which does not work,
    can anyone explain me about this.

    <html>
    <head>
    <script>
    function chk(e){
    if (e.keyCode==9){
    c = document.getElementById('code');
    d = c.value ;
    d = d + "\t";
    // d = d+" " ;
    c.innerHTML = d ;
    //alert (d);
    }
    }
    </script>
    </head>

    <body>
    <textarea id="code" onkeydown="chk(event)" rows=20 cols=60></textarea>
    </body>
    </html>
     
    pra__, Jul 14, 2008
    #1
    1. Advertising

  2. pra__ schreef:
    > I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
    > when a 'tab' key is pressed. I have this code, which does not work,
    > can anyone explain me about this.
    >


    Google for element.createTextRange

    JW
     
    Janwillem Borleffs, Jul 15, 2008
    #2
    1. Advertising

  3. pra__ wrote:
    > I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
    > when a 'tab' key is pressed. I have this code, which does not work,


    "Does not work" is a useless error description.

    > can anyone explain me about this.
    >
    > <html>
    > <head>
    > <script>


    Your markup is not Valid to begin with.

    <http://validator.w3.org/>

    > function chk(e){
    > if (e.keyCode==9){
    > c = document.getElementById('code');
    > d = c.value ;
    > d = d + "\t";
    > // d = d+" " ;
    > c.innerHTML = d ;


    Appending the Tab character to the content of a `textarea' element will add
    whitespace that is always interpreted as a single space in HTML. You should
    modify the value of the `value' property instead:

    c.value += "\t";

    However, the Tab character is not uniformly rendered. If you want to put in
    4 spaces, you should do exactly that:

    c.value += " ";

    And if it is your intention to insert 4 spaces at the caret position
    instead, you should use your favorite search engine to look up the
    corresponding FAQ entry. The suggested createTextRange() method will
    only help with MSHTML, and the FAQ entry also is more verbose.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Jul 15, 2008
    #3
  4. pra__

    pra__ Guest

    On Jul 16, 12:32 am, Thomas 'PointedEars' Lahn <>
    wrote:
    > pra__ wrote:
    > > I am developing a WYSIWYG editor using JS. I want to put in 4 spaces,
    > > when a 'tab' key is pressed. I have this code, which does not work,

    >
    > "Does not work" is a useless error description.
    >
    > > can anyone explain me about this.

    >
    > > <html>
    > > <head>
    > > <script>

    >
    > Your markup is not Valid to begin with.
    >
    > <http://validator.w3.org/>
    >
    > > function chk(e){
    > >   if (e.keyCode==9){
    > >       c = document.getElementById('code');
    > >       d = c.value ;
    > >       d = d + "\t";
    > >        // d = d+"    " ;
    > >       c.innerHTML = d ;

    >
    > Appending the Tab character to the content of a `textarea' element will add
    > whitespace that is always interpreted as a single space in HTML.  You should
    > modify the value of the `value' property instead:
    >
    >   c.value += "\t";
    >
    > However, the Tab character is not uniformly rendered.  If you want to put in
    > 4 spaces, you should do exactly that:
    >
    >   c.value += "    ";
    >
    > And if it is your intention to insert 4 spaces at the caret position
    > instead, you should use your favorite search engine to look up the
    > corresponding FAQ entry.  The suggested createTextRange() method will
    > only help with MSHTML, and the FAQ entry also is more verbose.
    >
    > PointedEars
    > --
    > var bugRiddenCrashPronePieceOfJunk = (
    >     navigator.userAgent.indexOf('MSIE 5') != -1
    >     && navigator.userAgent.indexOf('Mac') != -1
    > )  // Plone, register_function.js:16


    Got it, Thanks :)
     
    pra__, Jul 16, 2008
    #4
    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. Hermit Dave
    Replies:
    0
    Views:
    473
    Hermit Dave
    Jan 22, 2004
  2. Marvin Massih

    "Keycode DLL not found or invalid keycode"

    Marvin Massih, Dec 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,158
    Marvin Massih
    Dec 31, 2004
  3. News Sympatico
    Replies:
    0
    Views:
    328
    News Sympatico
    May 21, 2005
  4. tab 2 into tab 4 ?

    , Jun 19, 2005, in forum: Python
    Replies:
    2
    Views:
    355
  5. sfp
    Replies:
    1
    Views:
    534
    mrcakey \(The Eclectic Electric\)
    Feb 5, 2007
Loading...

Share This Page