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!

how to disable enter(return key) ?

Status
Not open for further replies.

ooops

MIS
Dec 21, 2000
91
US
Hi all,

in my application I have mutiple radio buttons(1 is checked as default) for zoomIn/Out/Pan....the image and a text box & button for query. Evetytime i put something in the textbox and hit enter, it submit the form and executes the code of the checked radio button. Is there a way to disable the enter key ? or make it execute the code for the button only (even when the radio button is checked) ? Any help is deeply appreciated.

 
you can set a global variable or hidden field onClick of the button you want to submit with, then in the onsubmit handler return false if that flag is not found. This way you know if they submitted the form the way you wanted them to jared@aauser.com
 
I don't think you can capture enter in an input type=text field. I've tried and tried, am I missing something Tom? In a textarea its easy, just test window.event.keyCode against 13, but I can't get it to work in input type=text fields. jared@aauser.com
 
Hitting enter in a <textarea>, as far as I know, cannot submit the form anyway. That is outside the browser control as it is part of an OS element. The enter key only causes a newline in textareas. Everything which actually effects the browser, however, should be susceptible to the event.keyCode method, including <input type=&quot;text&quot;> boxes. Have you tried setting the onkeypress handler?
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Yeah, like 400 times :)

What I just realized is that onkeydown will recognize an enter key press, but doesn't allow me to affect the submission at all, because the submission is occuring on keypress (after both keydown and keyup).

Because the submission occurs in the onkeypress, and not the keydown or keyup, I don't think we can affect this behavior at all. jared@aauser.com
 
Hi,

Sorry for my very limited knowledge about programming, it seems I do not completely know what to do. To make it simple, if i want to form not to be sumitted when user hits enter, what should I write ? some sample codes would be great. Thanks so much. Again, sorry, I'm still in school for MIS degree.
 
Yeah! I too faced the same problem recently.

1. Changed the submit button to a normal button and added an client side Javascript function which takes care of the button on_click event.

2. In the on_click event, fire the equivalent of a submit.

Here you go..

function btnSubmit_onclick()
{
document.formID.action &quot; document.formID.submit();
}
</script>

and for the button;
<input type=button id=btnSubmit name=btnSubmit value=&quot;Submit&quot; onClick=&quot;btnSubmit_onclick();&quot;>

Make sure you add form ID in the form tag like this and onsubmit = false also.
<form method=&quot;post&quot; action=&quot;&quot; name=&quot;form&quot; id=&quot;formID&quot; onSubmit=&quot;return false&quot;>

and for the button,
 
That's what I usually use as a solution also, it works pretty well, but I think it makes an annoying beeping noise when you press enter in the form :( jared@aauser.com
 
Try this:

<FORM NAME=&quot;form1&quot; OnSubmit=&quot;return false&quot;>
<INPUT NAME=&quot;entry&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;SubmitForm&quot; onClick=&quot;document.form1.submit()&quot;>
</FORM>
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Hi,

Thank you all for your helps. I find it very helpful however I still haven't been able to make it works for my application. I did what you suggested and it's true that when I hit enter the form is not submitted but when I click on the map to zoomIn/out, the form is also not submitted anymore. Just keep you posted, I'll continnue to work on it. Again, million of thanks. Sincerely,
Bao Nghi
 
hey, just read the above thread (if it has moved : thread216-43263) : to disable the form submit on pressing enter; just use netscape !!!!
 
iza...minor problem with that approach...Netscape 6 now works like IE and handles the enter key the same way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top