View Full Version : Automatically insert the cursor in to a text field

Jul 20th, 2010, 03:06 PM

Ok basically i have a question, i have had a quick look through Google, but i amnot sure if this is even possible. I have an online form which has an auto complete function on it. Once you start typing in the product title the products, a price and description appears in a drop down panel. Once you click on the product the information is entered in to the relevant form fields.

What i want to do is once the items have been entered in to the relevant fields i want to automatically place the cursor in to the qty box, but i am not sure if this is possible.

Any suggestions would be appreciated.

Jul 20th, 2010, 03:52 PM
Put this on the bottom of the page, just before ending your body tag:

<script type="text/javascript">
function formfocus() {
window.onload = formfocus;
And add the id "aotoFocus" to the input you want to focus on.

Jul 20th, 2010, 04:36 PM

Although i can not get it to work, but i have lots of code on the form because it has an auto look up feature and so i wonder if that could be the problem, the form is here:


Jul 20th, 2010, 07:49 PM
I see what you mean about a lot of code! I obviously haven't looked at all that but I did notice:

<input name="qty" type="text" id="autoFocus" size="5" onchange ="calcTot()" />

Your final script uses:


The two IDs don't match so change autoFocus to qty.

Jul 21st, 2010, 01:51 PM
Hi Thanks,

I have tried several things but no matter what changes i make i juyst can not seem to get it to work, i am begining to belive it is impossible.

Jul 21st, 2010, 02:04 PM
ID is supposed to be different for each element. Thats why its getElementById .
Give your qty id'd elements a name and use getElementsByName("NAME") instead of getElementById

Jul 21st, 2010, 03:59 PM
Inside of every third fill function add this

where the 1 is the appropriate number of the qty box so for the fill3 method you would add
For the fill6 method you would add

You probably didn't have to make a fill function for each input box but that was your choice.

And no its not impossible.