Wednesday, July 24, 2013

javascript autofocus form element on page load

hello
it’s very simple to dot he trick:
<input autofocus="autofocus" type="text" id="user" name="user" size="16" />
note: The autofocus attribute is supported in all major browsers, except Internet Explorer and Opera.
for Internet Explorer and Opera you can add along with the code:
<script type="text/javascript">
//<![CDATA[
   document.getElementById("user").focus();
//]]>
</script>
Note: The autofocus attribute is a boolean attribute, and can be set in the following ways:
HTML5
    <button autofocus>
    <button autofocus="autofocus">
    <button autofocus="">
———————————————————————-
* text string is automatically highlighted upon user focus:
<form action="http://site.com/" method="post">
   <div>
      <input onfocus="this.select();" value="Select this input text will be highlighted.." size="55" type="text">
   </div>
</form>
Example:
that’s it.

No comments:

Post a Comment