Snippets v2

Languages
My Snippets

Focus and select text in an Input field Login or Register to Bookmark this snippet

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();
  7.         elm.select();
  8.     }
  9. }
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment