Setting focus on field.

Hi experts,
  I m looking for setting focus on particular field.
How many ways we can do it?
Basically I want to without javascript or may be without using onLoad event?


LVL 11
ManishLeadAsked:
Who is Participating?
 
TimYatesCommented:
>> There is no other way AFAIK.

Yes there is...

Put the javascript inline...

ie:

<html>
  <head><title>Woo!?</title></head>
  <body>
    <form>
      <input type="text" name="firstParam"><br>
      <input type="text" name="secondParam" id="focusMe"><br>
    </form>
    <script type="text/javascript">
      document.getElementById( 'focusMe' ).focus() ;
    </script>
  </body>
</html>

Should work too..
0
 
ManishLeadAuthor Commented:
Basically I want  without using javascript or may be without using onLoad event?
0
 
fargoCommented:
you have to use onload like the following:

<body onload="document.Formname.fieldname.focus();" >
...
..
</body>

There is no other way AFAIK.

fargo
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
KuldeepchaturvediCommented:
you can try using TABINDEX property of HTML as well..
set it to 1 to get the focus..
0
 
fargoCommented:
Tim, I mean to say that there is no other way of doing this (except javascript).
I don't know whether tabindex will work!

fargo
0
 
TimYatesCommented:
>> Tim, I mean to say that there is no other way of doing this (except javascript).

Sorry, I thought you meant there was no other way but the onLoad event ;-)
0
 
KuldeepchaturvediCommented:
went thru the DHTML reference library...  
object.focus() method is the only way to setting the focus on any element..
0
 
ManishLeadAuthor Commented:
Thank you,
  I will get back to u guys.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.