This is a discussion on How do I set the focus to the first form field? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; How do I set the focus to the first form field?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| u can set focus to the first form field by using the following javascript function after the first form element "form_field_name" <script> document.getElementById('form_field_name').focus() ; </script> where "form_field_name" is the first form field ID
__________________ J.Vijayanand |
| |||
| You cannot do this with HTML. However, you can include a script after the form that sets the focus to the appropriate field, like this: <form id="myform" name="myform" action=...> <input type="text" id="myinput" name="myinput" ...> </form> <script type="text/JavaScript"> document.myform.myinput.focus(); </script> A similar approach uses <body onload=...> to set the focus, but some browsers seem to process the ONLOAD event before the entire document (i.e., the part with the form) has been loaded |
| |||
| Hi, We can set the focus to the first form field by using this code... U can try this code where u need... hope u get better result... Here Codes, <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function toForm() { document.form.field1.focus(); } </script> </HEAD> <BODY onLoad="toForm()"> <FORM NAME="form" METHOD="POST" ACTION="#"> <SELECT NAME="field1" SIZE="1"> <OPTION VALUE="one">Field 1 <OPTION VALUE="two">also field1 </SELECT> <BR> <INPUT TYPE="TEXT" NAME="field2" SIZE="10"> Field 2<BR> <INPUT TYPE="TEXT" NAME="field3" SIZE="10"> Field 3<BR> <BR> <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Submit"> <INPUT TYPE="RESET" onclick="toForm();"> </FORM> <p><center> <font face="arial, helvetica" size"-2">Free JavaScripts provided<br> by <a href="http://javascriptsource.com">The JavaScript Source</a></font> </center><p> </BODY> </HTML>
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/html-css-javascript-coding-techniques/2947-how-do-i-set-focus-first-form-field.html | |||
| Posted By | For | Type | Date |
| DiscussWeb IT Community - Fusing | This thread | Refback | 08-08-2007 04:10 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date/time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-06-2008 10:16 PM |
| Date/Time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 01-17-2008 08:47 PM |
| How can I clear the form field values after the user has submitted the form for clien | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-01-2007 11:39 PM |
| How can I set the value of a fileupload form field? | kingmaker | HTML, CSS and Javascript Coding Techniques | 0 | 10-31-2007 03:08 AM |
| How can I uncheck a radio form field? | Pvinothkumar | HTML, CSS and Javascript Coding Techniques | 1 | 10-17-2007 11:25 PM |