not getting focus in textarea.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dinesh1985singh
    New Member
    • Apr 2010
    • 49

    not getting focus in textarea.

    I want to place a cursor by default in a textarea.The editor is in a hidden div, and when a button is clicked, the div displays. Instead of making the user click in the editor to begin typing, I want the editor focused so they can start adding content immediately.
    Last edited by Niheel; Jun 1 '10, 12:29 PM. Reason: Hello and thank you removed.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I’d guess you should apply .focus() to the editor’s <textarea>

    Comment

    • dinesh1985singh
      New Member
      • Apr 2010
      • 49

      #3
      Originally posted by Dormilich
      I’d guess you should apply .focus() to the editor’s <textarea>
      Thank you Dormilich ,but it didn't work.I tried it.


      I you would have any other alternetive then please let me know..
      thank you

      Comment

      • phvfl
        Recognized Expert New Member
        • Aug 2007
        • 173

        #4
        Originally posted by dinesh1985singh
        Thank you Dormilich ,but it didn't work.I tried it.


        I you would have any other alternetive then please let me know..
        thank you
        Should be working for you. Given html of
        Code:
        <div id="editorDiv" style="display:none;">
        <textarea id="myEditor" name="myEditor" cols="30" rows="6"></textarea></div>
        The following javascript should do what you want:
        Code:
          var container = document.getElementById("editorDiv"), editor = document.getElementById("myEditor");
          container.style.display="block";
          editor.focus();

        Comment

        Working...