We help IT Professionals succeed at work.

Setting focus on field.

Manish
Manish asked
on
Medium Priority
255 Views
Last Modified: 2010-04-01
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?


Comment
Watch Question

ManishLead
CERTIFIED EXPERT

Author

Commented:
Basically I want  without using javascript or may be without using onLoad event?

Commented:
you have to use onload like the following:

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

There is no other way AFAIK.

fargo
you can try using TABINDEX property of HTML as well..
set it to 1 to get the focus..
CERTIFIED EXPERT
Top Expert 2004
Commented:
>> 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..

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Commented:
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
CERTIFIED EXPERT
Top Expert 2004

Commented:
>> 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 ;-)
went thru the DHTML reference library...  
object.focus() method is the only way to setting the focus on any element..
ManishLead
CERTIFIED EXPERT

Author

Commented:
Thank you,
  I will get back to u guys.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.