Feedback on: irt.org FAQ Knowledge Base Q1179
Worth:
Worth reading
Length:
Just right
Technical:
Just right
Comments:
There is a typo in the example code:
onKeyPress=keyhander(e)
"keyhander" should be written as
"keyhandler"
Worth:
Not worth reading
Comments:
any form with two text inputs will not be submitted when enter is pressed....
if you remove one of the text fields, the form still submits on enter
Worth:
Very worth reading
Length:
Too short
Technical:
Not technical enough
Comments:
I couldn't get the example to work. First there is an extra quote after keyhander(e) call and then it says that e is undefined. Am I doing something wrong here?
Worth:
Very worth reading
Comments:
The solution provided works for me on one machine and not on another. Both are using the same version of IE. The thing I dont understand is how do you have an 'if' statement outside of the function. Also, you're passing 'e' into keyhandler. How does the program know what 'e' is? I receive an error 'e' is an undefined object. Although on my Computer at work...it works fine. How is this possible. If its undefined....its undefined, it doesnt seem like it should work anywhere. Also I am unfamiliar what the 'e ? e' is. Can you please explain? Thanks
Brian
Worth:
Worth reading
Comments:
However, it doesn't seem to work.
For one, the example shown has some obvious errors.
keyhandler is misspelled.
It is spelled "keyhander" (missing 'l') in the OnKeyPress
Second, there is only ONE quote (") at the end...but not at the beginning of the OnKeyPress.
After fixing that for my use, it still doesn't work in IE5. I have tried using this, and the only thing that seems to happen is the "Submitted" pop up box comes up....instead of denying the user the ability to press enter to submit the form.
Please advise the correct way to solve this problem in IE5.
(How to disallow the user from submitting a form by pressing the enter key)
Thanks
Rich
Worth:
Not worth reading
Comments:
does not stop submission in IE.
Worth:
Very worth reading
Comments:
Use:
onkeypress="keyhandler(event)"
Worth:
Very worth reading
Length:
Too short
Comments:
In theory very worth reading
because it is supposed to do want
I need to do..
BUT, firstly the script contains
an error. It could never work.
The function is called KeyHandler
but the calls are 'keyhander'..
Secondly there is no explanation
of it's component parts which is
poor and finally it just doesn't work. Can't work out why but it
never catches the ENTER key...
Worth:
Worth reading
Comments:
I've finally managed to get that
wretched script to work. I'm glad 'm not
working with the person who posted
it. Doesn't say a lot for their work.
I'm using IE 4.472/SP1,
apart from the obvious syntax error. I got the script to work
as such:-
onKeyPress="return keyhandler(event)"
in your INPUT tags.
The guy who said the behaviour goes away when more than one txt
control is on the form must be using IE5 or a different build.
I've not tested on IE5 yet.
Comments:
The Enter Key is the default keyboard shortcut for a submit button so try the following:
<html>
<head>
<script language=JavaScript>
</script>
</head>
<body>
<form method=post name=form_name action=test.pl>
<input type=text size=20>
<input type=text size=20>
<input type=text size=20>
<input type=button value=Submit onClick="submitForm();">
</form>
</body>
</html>
Basically, we are replacing the submit button with a standard button and using JavaScript to submit the form when the button is pressed.
The enter key will still submit the form, but ONLY if the submit button has the focus (i.e. the user has tabbed onto the button).
Unfortunately I think IE 4.0.72 has some problems with using javascript to submit a form.
Worth:
Worth reading
Length:
Just right
Technical:
Not technical enough
Comments:
Doesn't work though. Ended up coming up with a solution by myself that works fine, and is, forgive me, rather elegant.
Try:
<SCRIPT LANGUAGE="JavaScript">
function doButtonMethod() {
form1.submit();
}
</SCRIPT>
<FORM name="form1" method=post action="nextpage.html">
<INPUT TYPE="TEXT" name=text1>
<INPUT TYPE="button" onclick="doButtonMethod();" value="Submit">
</FORM>
Worth:
Not worth reading
Comments:
I have been unable to get this to work on my IE 5.xxx.
Does anyone have a version that does work?
JSf
Here is the last code I tried to get working.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript"></script>
</head>
<body>
<form name="myForm" onSubmit="alert('submitted'); return false;">
<input type="text" name="field1" onkeypress="keyhandler(window.event)">
<input type="text" name="field2" onkeypress="keyhandler(window.event)">
<input type="submit" value="eat me">
</form>
</body>
</html>
Technical:
Not technical enough
Comments:
Much better solution:
http://www.cs.tut.fi/~jkorpela/forms/enter.html
Worth:
Very worth reading
Length:
Technical:
Comments:
Works, but in IE6 the function "submitForm();" must be "submit();".
Worth:
Very worth reading
Length:
Technical:
Comments:
this item was also useful while I was trying to incorporate a javascript confirm box and the form would keep on submitting even when the user would press "cancel" on the confirm box.
What I did was
my submit button
input type = button, onClick= return checksubmit(form);
function checksubmit(form){
var resp = confir("do you say yes or no")
if( resp == true){
form.submit()
}
else {
do whatever u like...
}
}