Focus and select text in an Input field

Description Javascript

This function not only focuses the cursor to an input field, but also selects all text within.

May cause errors if supplied element is not an text, password or textarea field.

Requires xGetElementById (also available on this site).

The Code Download

  1. function jFocus(elm) {
  2.     if(typeof(elm) == 'string') {
  3.         elm = xGetElementById(elm);
  4.     }
  5.     if (elm) {     
  6.         elm.focus();
  8.     }
  9. }


Added by JC on 12th November 2007


There are no comments about this snippet.

Post Comment Github Markdown Supported

You must be logged in to post a comment.

Login here to post a comment