Keep focus after submit

R

Robert Scheer

Hi.

I have a function to submit the form when my user types any character
on a textbox. I call the function on the keyup event of the textbox.
The function submits the form and set the focus on the textbox, after
the submit. The form submits ok, but after the submit the focus won't
return to the textbox. Can anyone help me to solve that problem?
That's the function:

<Script language='Javascript'>
function checkaddress(txt)
{
if (txt.value.length == 1) {
document.Form1.optAdd.checked=true;
document.Form1.submit();
txt.focus(); }
else { return false; }
}
</Script>


Thanks,

Robert Scheer
 
G

Grant Wagner

Robert said:
Hi.

I have a function to submit the form when my user types any character
on a textbox. I call the function on the keyup event of the textbox.
The function submits the form and set the focus on the textbox, after
the submit. The form submits ok, but after the submit the focus won't
return to the textbox. Can anyone help me to solve that problem?
That's the function:

<Script language='Javascript'>
function checkaddress(txt)
{
if (txt.value.length == 1) {
document.Form1.optAdd.checked=true;
document.Form1.submit();
txt.focus(); }
else { return false; }
}
</Script>

Thanks,

Robert Scheer

Once you've submitted the form, you've navigated away from the page.
JavaScript will stop executing and the browser will load the page
specified by the ACTION attribute of the <form> element.

While some browsers may actually execute txt.focus() as the form
submission occurs, it's more of a bug then a feature.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,076
Messages
2,570,565
Members
47,201
Latest member
IvyTeeter

Latest Threads

Top