PDA

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



stn003
Jul 20th, 2010, 03:06 PM
Hi,

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.

nikee
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() {
document.getElementById('element').focus();
}
window.onload = formfocus;
</script>
And add the id "aotoFocus" to the input you want to focus on.

stn003
Jul 20th, 2010, 04:36 PM
Thanks,

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:


http://95.131.66.39/~pestcont/autosearch/form_new.html

Thanks
stn

DaiLaughing
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:


document.getElementById('qty').focus();

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

stn003
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.

Candan
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

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

$("qty1").focus()
where the 1 is the appropriate number of the qty box so for the fill3 method you would add
$("qty").focuse()
For the fill6 method you would add

$("qty2").focus()
etc...
You probably didn't have to make a fill function for each input box but that was your choice.

And no its not impossible.