Normally, when users click on any label tag with the cursor, the corresponding input field will be focused ready for input or selection. Therefore, you can always achieve the focus effect by this native function of HTML’s. Otherwise, you’d need a small dime of JavaScript to set focus to any form element on the fly upon a certain event:
// FormName is the name value of the form.
// FieldName is the name value of the field
// to be focused.
document.FormName.FieldName.focus();
Or by element ID:
// FieldId is the id value of the field
// element to be focused.
document.getElementById('FieldId').focus();
There you go, the tiny focus() function is what we all need.
You should also read:
- JavaScript: Confirmation / Warning before Leaving or Navigating Away from a Page
- DOM event detection: event bubbling and event capturing
- HTML: Make Content Editable in Element / Tags without JavaScript
- CSS: Styling File Upload / Select Input Control <input type="file" … />
- PHP: File Upload Script (HTML Form + PHP Handler Class)


Facebook
Twitter
Google Plus