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

How to select submit button so Enter can submit form?

Status
Not open for further replies.

yergnov

Technical User
Nov 8, 2001
7
US
I have a page with a form which includes a list and a menu- each with ~40 objects. Here are the properties of the form:
<form action=&quot;htm_account_summary.asp&quot; name=&quot;Account&quot; method=&quot;post&quot; onSubmit=&quot;return VerifyData()&quot;>

I would like to be able to have the submit button highlighted so that users select something from the menu and hit enter rather than have to hit the submit button. with the mouse. How can I get this done?

Thanks in advance for your help.
 
<form name=&quot;myform&quot; METHOD=&quot;post&quot; ACTION=&quot;<input type=&quot;text&quot; name=&quot;textfield&quot;>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;>
</form>

<script language=javascript>
document.onkeydown=go_submit();
function go_submit() {
var key= event.keyCode;
if(key == 13) { // 13 = enter key
document.forms['myform'].submit(); // submit myform form
}
}
</script>



Although don't most browsers post the form when enter is hit?


When in doubt, deny all terms and defnitions.
 
yup if your button has a submit value then enter will post that for.

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
I tried the JavaScript and it did not work. I notice when I choose one of the items in my list, the submit button is highlighted (darkened edges) but the enter button will not work to submit the page. I am running the following to check that there is a value selected in each of my menus:

function VerifyData()
if (document.frmAccount.account_id.value == &quot;0&quot;)
{
alert(&quot;You must select an account&quot;);
return false;
}
{
if (document.frmAccount.contact.value == &quot;0&quot;)
{
alert(&quot;You must select a contact&quot;);
return false;

Note- This works. In my copy/paste, I deleted some of the &quot;)&quot; for space reasons.

Can this be causing my problems?

 
Got that. I eliminated them for practical purposes on my posting. I need to know if this script (which does work) preempts my efforts to use the submit button properly. Do I need to include a new 'if' and use your submit function
within the &quot;VerifyData&quot; function?

Thanks again- this is helpful.
 
Ok, I tried that but it didn't seem to work. If I include a blank text field on my form and am in that with my cursor, Enter works. If I am in any of the other two objects (list and menu), Enter does not work. Any other ideas?
 
Well, yes.. you have to be in the form for ENTER to work. I don't know of any workaround for that.

When in doubt, deny all terms and defnitions.
 
Aren't the list and menu objects considered to be within the form? They fall between the tags <form></form>.
 
I should have been more clear... the cursor needs to be in a form field, which it would be if the person was entering info anyway.

When in doubt, deny all terms and defnitions.
 
Outta luck it sounds like. Thanks for your help.

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top