Text box question

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
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Text box question

Post by oldtimer »

I have heard there is a way to put the curser in a certain text box automatically so that the end user does not have to click in the text box.

I have seen some javascript that will put it in the first field but if I have several and want that one then this script will not work.

Any ideas?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

1. Should be posted in ClientSide part of this forum...
2. You can still use Javascript. Use it as a function on top of the page, and the call it in the text-field of choise using the onload() event or similiar.

More info on the net
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post by gite_ashish »

I guess, you are looking for following:

<HTML>
<BODY onLoad="document.frm.txt1.setFocus();"> <!-- ** ** -->
<FORM name=frm>
First nane: <INPUT type=text name=txt1>
Second name: <INPUT type=text name=txt2>
House #: <INPUT type=txt name=txt3>
Street #: <INPUT type=txt name=txt4>
<INPUT type=submit>
</FORM>
</BODY>
</HTML>
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

I did not post it in client side as I was hopping there was a way to do it in PHP.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Still yes and no. (For others that might read the post:)
As gite_ashish pointed out, a body's onload would solve it.

PHP can in this case be used for example; counting the amount of form-fields shown, and give you a number/name of a field you might want to set focus to.

But as PHP does not do anything with the visual states, Javascript is needed to do the actual focusing. PHP is server-side, so you can in theory only set the focus on the server, if there was anything to focus on... =)

Hope it helped tho.
Post Reply