Hi,
Im trying to fix my forms so that enter does not submit forms on IE/Mozilla/Safari but cannot find a solution. First off I used :
/*--- Disable enter key ----*/function kH(e) { var pK = e ? e.which : window.event.keyCode;return pK != 13;} document.onkeypress = kH;if (document.layers) document.captureEvents(Event.KEYPRESS);/*------------*/
on all pages but it didnt seem to work. So then I decided to try catch the keypress from forms like input and textarea and I used the following (onkeypress="return ifEnter(this,event);")
function ifEnter(field,event) { var theCode =event.keyCode ?event.keyCode :event.which ?event.which :event.charCode;if (theCode == 13) {return false; }else {return true; }}
but again it doesnt seem to work. Another thing I noticed is that it seems to submit the form as asp.net would. My default form submission is a next button which moves to another page when submitted, but when someone hits enter, the same page reloads with a standard postback i think.
What I want to know is why the javascript wont work? Is it because the form is in an updatepanel? How can I manage the user pressing enter in an update panel?
Why doesnt the user pressing enter activate the DefaultButton action of the panel which its in?
All help much appreciated!
C
Edit: never mind, I see the behavior now.
I saw the behavior with only one textbox. Adding a second set to invisible, perhttp://aspnet.4guysfromrolla.com/articles/060805-1.aspx, fixed it.
See if that helps for you.
My form allready had multiple textboxes etc.
The problem seesm to be only in firefox. Ive found a partial fix for my problem which at least submits my default button and saves the form instead of performing a callback here :
http://www.andornot.com/about/developerblog/2007/09/fix-firefox-defaultbutton-issue-with.aspx
Im still looking for a simple way to prevent enter key form posting back in certain textareas or input text boxes in firefox pretty please.
No comments:
Post a Comment