Tab keycode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pra__

    Tab keycode

    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.getEle mentById('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>
  • Janwillem Borleffs

    #2
    Re: Tab keycode

    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.createT extRange

    JW

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Tab keycode

      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.or g/>
      function chk(e){
      if (e.keyCode==9){
      c = document.getEle mentById('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 bugRiddenCrashP ronePieceOfJunk = (
      navigator.userA gent.indexOf('M SIE 5') != -1
      && navigator.userA gent.indexOf('M ac') != -1
      ) // Plone, register_functi on.js:16

      Comment

      • pra__

        #4
        Re: Tab keycode

        On Jul 16, 12:32 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
        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.or g/>
        >
        function chk(e){
          if (e.keyCode==9){
              c = document.getEle mentById('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 bugRiddenCrashP ronePieceOfJunk = (
            navigator.userA gent.indexOf('M SIE 5') != -1
            && navigator.userA gent.indexOf('M ac') != -1
        )  // Plone, register_functi on.js:16
        Got it, Thanks :)

        Comment

        Working...