Email
Share

We Rock Your Web Forum » Web Programming

How to auto select all on an input field?

(2 posts)
  1. JeffNox

    member
    Joined: Aug '09
    Posts: 24

    I'm trying to figure out how I can get an input field to have all its content auto selected when a user simply clicks on it once. This will prevent the user from having to drag the mouse to select, and inadvertently not select the whole line.

    I've seen this implemented on several sites but am unsure of how it's done. Any help is much appreciated!

    Posted 2 years ago #

  2. Posted 2 years ago
  3. Anonymous



    Hi there,

    This is fairly simple to implement. Simply add the following Javascript statement to your page header (the page on which you want the auto select functionality):

    <script type="text/javascript">
    function highlight(field) {
    field.focus();
    field.select();
    }
    </script>

    Next, add the following Javascript statement to the input field you want auto select applied to:

    <input onClick="highlight(this);" size="50" type="text" />

    Posted 2 years ago #

RSS feed for this topic

Reply

(required)

Allowed markup: BBcode blockquote code em strong ul ol li font strike center u hr.
You can also put code in between backtick ( ` ) characters.