Click to See Complete Forum and Search --> : How do I position the cursor on a control in my page?
I have a textbox I've named 'userid' in the 3rd row 2nd column of a table.
I would like the cursor to be there when ever the page loads.
I've done some looking around but can't seem to find an answer that doesn't require lots of extra code. Surely there is a one line statement that can set the cursor location.
In VB I use the SetFocus method to set the focus to the desired control.
PLEASE HELP.
Cheers,
Nap
Brooksie155
03-08-2006, 07:31 AM
In the body tag add the following:
onload="document.FORM_NAME.userid.focus( )"
N.B. you will need to replace FORM_NAME, with the name of the form 'userid' is encapsulated within.
thnx Brooksie155 for that.
However, I don't have a form name. Just a title.
Cheers,
Nap
bokeh
03-08-2006, 07:52 AM
<form action="" method="POST">
<input id="myInput" type="text">
</form>
<script type="text/javascript">document.getElementById('myInput').focus();</script>
Hi Brooksie155,
Thanks for your help.
However, since I don't have a form name just a title, the line you gave me didn't work. It was close. I searched another site and came up with this (which now works):
<body onload="document.all.name_of_control.focus()">
Using all in place of a form name I was able to make it work.
Bokeh,
I found the above before you posted. Thanks for you info.
Cheers,
Nap
bokeh
03-08-2006, 08:08 AM
Hi Brooksie155,
Thanks for your help.
However, since I don't have a form name just a title, the line you gave me didn't work. It was close. I searched another site and came up with this (which now works):
<body onload="document.all.name_of_control.focus()">
Using all in place of a form name I was able to make it work.
Bokeh,
I found the above before you posted. Thanks for you info.
Cheers,
Nap
Ok, but your code will not work if the page is served with an application/xhtml+xml mime/type. Also document.all is MSIE only. Get yourself a decent browser like Firefox to test in.
Lol Bokeh,
I am already using Firefox to test it.
Cheers,
Nap
john_de116
03-09-2006, 03:56 AM
<body onload="document.getElementById('txt_user').focus()">
Try this. It will work as you like.
John,
I was able to get it going. A little different from what you suggested, but it's working in Firefox and IE6.
Check my 2nd last post.
Cheers,
Nap
bokeh
03-09-2006, 06:47 AM
John,
I was able to get it going. A little different from what you suggested, but it's working in Firefox and IE6.
Check my 2nd last post.
Cheers,
Napdocument.all should not be used. It is browser specific.
SpectreReturns
03-09-2006, 09:49 PM
Just FYI, anything that needs to be done on the client side shouldn't be posted in the PHP forum.