[SOLVED] JS Selstart?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

JS Selstart?

Post by Joe »

I was trying to look for a javascript reference that tells me how to selstart a text box. Im sure that 'selstart' is the name for it. What it does is when the user visits the page it automatically puts the text pointer into the username text field. i have seen it in action before but I just can't seem to do it myself. Can anyone please guide me in the right direction here?

Any help appreciated!


Joe 8)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I usually just put the following after the closing </form> tag :
<script language="JavaScript">document.aform.atitle.focus();</script>

Where 'aform' is the name of the form and 'atitle' is the field to get focus. Eg

Code: Select all

<form name="aform" method="post">
<input type="text" name="atitle" value="" />
</form>
<script language="JavaScript">document.aform.atitle.focus();</script>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Code: Select all

<script>
<!--
function sf()&#123;document.form_name.textbox_name.focus();&#125;
// -->
</script>
and then

Code: Select all

<body onLoad=sf()>
form_name is the name of your form that the textbox is in
textbox_name is the name of the textbox or any control that you want to set the focus for.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Very nice indeed :). Thanks alot guys, problem solved. hehe
Post Reply