Jump to content

enter key = submit


george

Recommended Posts

is there function to catch if the enter key is pressed like there is for the alt key or the ctrl key? I have a two field form. One of my bosses insists on having a submit button, the other boss insists on just pressing enter . But it looks like the only way I can test for pressing enter is to test every keystroke make in the field with a george made function call. There has to be a better way.

Link to comment
Share on other sites

<script type="text/javascript">function checkEnter(e){	e = (e) ? e : window.event;	var charcode = (e.which) ? e.which : e.keyCode;	if(charcode == 13)	{		alert("You hit ENTER!");	}}</script><input type="text" onkeydown="checkEnter(event);" />

Link to comment
Share on other sites

Thanks jeshjustsomeguy: I am using a AJAX function to submit the form. There is no actual submit button. But I am beginning to wonder if this method is actually better than just reloading the page with a submit? Since I am always on the same page, and make forms appear and get processed without ever submitting them, am I paying for this in performance loss? I have not seen any form object deconstructor. Have you heard of such a thing?

Link to comment
Share on other sites

Thanks jeshjustsomeguy: I am using a AJAX function to submit the form. There is no actual submit button. But I am beginning to wonder if this method is actually better than just reloading the page with a submit? Since I am always on the same page, and make forms appear and get processed without ever submitting them, am I paying for this in performance loss? I have not seen any form object deconstructor. Have you heard of such a thing?
TheContainerOfTheForm.removeChild(TheForm) , or TheContainerOfTheForm.replaceChild(newForm,oldForm)?
Link to comment
Share on other sites

Thanks jeshjustsomeguy: I am using a AJAX function to submit the form. There is no actual submit button. But I am beginning to wonder if this method is actually better than just reloading the page with a submit? Since I am always on the same page, and make forms appear and get processed without ever submitting them, am I paying for this in performance loss? I have not seen any form object deconstructor. Have you heard of such a thing?
You can still use that to run AJAX if you have the function inside the onsubmit event for the form. Then no matter how they submit the form it will execute the AJAX function. If that function returns a false value then it will also stop the form from reloading the page.
Link to comment
Share on other sites

I.e. use the onsubmit event handler of the form, so that the user does "submit" the form, but it is caught by your AJAX function that then returns false and prevents the page's location changing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...