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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP - Using the enter key to submit a form

Status
Not open for further replies.

SmileyFace

Programmer
Sep 10, 2002
99
0
0
US
I would really appreciate help with this....

I have a form on a page which has an image called 'Save' to submit it. This image currently calls another function called 'fsubmit' on the page which validates the form before submitting it. I need to use the 'Enter/Return' key to subit the form. Thus I cannot use the usual form submit as it doesn't have a parameter 'action' which sends it directly to another page.

So basically I need to be able ot use the 'Enter' key to submit a form where the submit button is an image which calls another function on the same page. PLEASE HELP. If there is a way to do this without using an image thats fine too. Thanks a lot in advance. Heres how some of the code looks...

-------This is part of a VBScript-------------------------
sub fReset
window.frmHouseHold.reset
end sub

sub fSubmit
if validform then
<%if ActionToTake = &quot;I&quot; then%>
window.frmHouseHold.action = &quot;HouseHoldEdit_Action.asp?fx=I&quot;
<%else%>
window.frmHouseHold.action = &quot;HouseHoldEdit_Action.asp?fx=U&household_id=<%=HouseHoldID%>&quot;
<%end if%>
window.frmHouseHold.submit
end if
end sub
-----------------------------------------------------------

-------This is the form------------------------------------
<form id=&quot;frmHouseHold&quot; name=&quot;frmHouseHold&quot; method=&quot;post&quot;>

<table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot;>
<tr valign=&quot;middle&quot;>
<td><font face=&quot;Arial&quot; size=&quot;2&quot; color=&quot;#FFFFFF&quot;><b>Address</b></font></td>
<td><input type=&quot;text&quot; name=&quot;txtAddress1&quot; size=&quot;35&quot; maxlength=&quot;35&quot; value=&quot;<%=txtaddress1%>&quot;></td>
</tr>
<tr valign=&quot;middle&quot;>
<td></td>
<td><input type=&quot;text&quot; name=&quot;txtAddress2&quot; size=&quot;35&quot; maxlength=&quot;35&quot; value=&quot;<%=txtaddress2%>&quot;></td>
</tr>
<tr valign=&quot;middle&quot;>
<td><font face=&quot;Arial&quot; size=&quot;2&quot; color=&quot;#FFFFFF&quot;><b>City</b></font></td>
<td><input type=&quot;text&quot; name=&quot;txtCity&quot; size=&quot;20&quot; maxlength=&quot;20&quot; value=&quot;<%=txtCity%>&quot;></td>
</tr>
<tr valign=&quot;middle&quot;>
<td align=&quot;right&quot; colspan=&quot;2&quot;>

<img border=&quot;0&quot; src=&quot;../../images/btnSave.jpg&quot; onclick=&quot;fsubmit()&quot; style=&quot;cursor:hand&quot;>
<img border=&quot;0&quot; src=&quot;../../images/btnReset.jpg&quot; onclick=&quot;freset()&quot; style=&quot;cursor:hand&quot;>

</td>
</tr>
------------------------------------------------------------
 
I guess you could have something like this:

Code:
<form id=&quot;frmHouseHold&quot; name=&quot;frmHouseHold&quot; method=&quot;post&quot; [b]onSubmit=&quot;fSubmit&quot;[/b]>

Then, to have an image for submission:

Code:
<input type=&quot;image&quot; value=&quot;Submit&quot; src=&quot;imagePath&quot;>

Let me know if this is what you were looking for ?
 
oops, tried to use bold in a code tag. ignore the
Code:
[b] and [/b]
 
<form id=&quot;frmHouseHold&quot; name=&quot;frmHouseHold&quot; method=&quot;post&quot; action=&quot;ThePage&quot; onsubmit=&quot;fsubmit()&quot;>


<img border=&quot;0&quot; src=&quot;../../images/btnSave.jpg&quot; onclick=&quot;document.frmHouseHold.submit()&quot; style=&quot;cursor:hand&quot;>




Known is handfull, Unknown is worldfull
 
Thanks Guys! Gatchaman, yours works but there seems to be one problem. For some reason on one of the forms which has just 3 combo boxes and a submit...if I hit enter on that screen it will not submit the information. If I click on the submit button it will go to the next screen. Then by hitting the back button if I go back to the previous screen and again try hitting the 'Enter' key to submit, it will work!! Why is this happening? Is there some way I can get it to work without having to click on submit? Thanks again for u're help.
 
Hmm, I'd have to look into that one about further, or maybe someone else could help. Seems that it if you have focus on a combo/select box, when you hit enter it wont submit (just tested it myself.).

No probs helping you, but I'm sorry I can't help with the next bit :(
 
That sucks! I broke my head trying to figure it out! Oh well....thanks again for your help....atleast it worked on other screens. The users will just have to deal with it! :)
 
Hey ScriptOHead! This looks like a good tutorial. Will check it out. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top