www.webdeveloper.com
Results 1 to 5 of 5

Thread: Placing cursor in comment field

  1. #1
    Join Date
    Aug 2008
    Posts
    3

    Placing cursor in comment field

    My comment field is at the end of several paragraphs below the lower screen edge. Using 'onload' naturally moves the page up and the opening paragraphs are out of sight.
    Any way to place the cursor in the field so the client does not have to click? Maybe after scrolling to a specified document place?
    I am stymied. Any help? thanks a bunch, horst22

  2. #2
    Join Date
    Nov 2006
    Location
    Springfield, MO
    Posts
    1,541
    You could do the following with JavaScript:

    Code:
    <script type="text/javascript">
      // set focus to form field
      document.forms[0].txtFullName.focus();
      document.forms[0].txtFullName.select();
    
    </script>
    Where txtFullName is the name of the form field where the cursor will automatically be placed. That's of course, if I understand the question correctly.

  3. #3
    Join Date
    Aug 2008
    Posts
    3
    Thanks a lot, but this 88 yr old beginner has a problem with 'name of form field'. II used the Textarea tag in the HEAD section as you can see. Here is my code:
    <form method="post" name="commentform">
    <FORM METHOD=POST ACTION="http://toolbox.omnis.com/bin/formmail.pl">
    <form method="post" name="commentform">
    <TEXTAREA NAME="request" ROWS="2" COLS="55"></TEXTAREA>
    <input type=hidden name="recipient" value="horst@bookandpoems.com">
    <input type="hidden" name="subject" value="A Confession">
    <input type=submit value="send to Horst" name=submit>
    <input type="hidden" name="return_link_url" value="http://shortstories.bookandpoems.com/index.HTML">
    <input type="hidden" name="return_link_title" value="Back to the SHORT STORY MENU">
    </FORM>
    Thanks for your help, horst22

  4. #4
    Join Date
    Nov 2006
    Location
    Springfield, MO
    Posts
    1,541
    Place the reference to your text area right before your ending </form> tag:

    Code:
    <input type="hidden" name="return_link_title" value="Back to the SHORT STORY MENU">
    <script type="text/javascript">
      // set focus to form field
      document.forms[0].request.focus();
      document.forms[0].request.select();
    </script>
    </FORM>
    Where request is the name that you've given to your text area.

  5. #5
    Join Date
    Aug 2008
    Posts
    3
    Thanks Ryan. I appreciate the lesson.
    It places the cursor where I wanted it but my main problem still remains and I have a hunch that it cannot be solved. The document text is more than one screen full. The comment field is at the end of the text. The cursor, naturally, moves the text up so that the visitor looks at the end instead of the start.
    Is there a way to either prevent that behavior, - or start the script after the visitor reaches the end of the document? I promise - no further question. Mahalo - thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles