Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit on pressing the enter key 2

Status
Not open for further replies.

jcbr

Programmer
Apr 19, 2001
12
US
Hello, I have an asp search page that contains several text fields, and upon user entry, submits the data to a db, and returns the results of that search. No big deal...however, I want to be able to have the form submit after I hit the enter key after entering info in any text box. Right now it will only do this when the very first text box has text entered and then the enter key is hit. I had to use 2 separate forms to get it to do this: One form contains the text box that will actually submit when the enter key is hit, the other form contains all the rest of the text boxes. I need to be able to submit when any text is entered in any box and the user hits enter. Any help is tremendously appreciated!
 
Hi jcbr,

you can use javascript,
here is the code:

<script language=&quot;JavaScript&quot;>
IE4 = (document.all);
NS4 = (document.layers);

if (NS4) document.captureEvents(Event.KEYPRESS);
document.onkeypress = ShortCut;

function ShortCut(e) {
whichASC = (NS4) ? e.which : event.keyCode;
switch (whichASC) {
case 13:
document.MyFormName.submit();
return false;break;
default:break;
}
}

hope this helps, Chiu Chan
WebMaster & Software Engineer
emagine solutions, inc
cchan@emagine-solutions.com
 
Thank you so much! That really helped. It works great in ie and netscape 4.x. Do you by any chance know what to do in Netscape 6? I cant get it to work there. Thanks again.
 
Hi jcbr,

try my new version, this should works for NS6 :)

<script language=&quot;JavaScript&quot;>
var IE4 = (document.all);
var NS4 = (document.layers);
var NS6 = (document.getElementById && !document.all)

if (NS4 || NS6) document.captureEvents(Event.KEYPRESS);
document.onkeypress = ShortCut;

function ShortCut(e) {
whichASC = (NS4 || NS6) ? e.which : event.keyCode;
switch (whichASC) {
case 13:
document.MyFormName.submit();
return false;break;
default:break;
}
}
</script>

hope this helps, Chiu Chan
WebMaster & Software Engineer
emagine solutions, inc
cchan@emagine-solutions.com
 
Hi Chiu,
Thanks again. With a few minor modifications, everything works!!! Thanks so much for all your talent and help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top