PDA

Click to See Complete Forum and Search --> : Enter Key problem


dadames
Nov 8th, 2000, 10:03 AM
My page has a form with some text controls and 2 submit buttons, the first one labeled Continue. The page submits to itself with each submit displaying new choices. For one such choice there is a text control, txtRemote, that has an onBlur event that calls a validation that resets its value to zero if the user enters more than 40000.

Here is a sequence that works correctly:
-user inputs 50000
-user clicks the Continue button (a submit)
-validation routine for txtRemote displays an alert and resets the 50000 to zero
-user clicks Ok or presses Enter to clear the alert
-the page is not submitted allowing the user to enter a new value in txtRemote

Here is a sequence that is incorrect:
-user inputs 50000
-user presses Enter key
-validation routine for txtRemote displays an alert and resets the 50000 to zero
-user clicks Ok or presses Enter to clear the alert
-the page submits to itself displaying new choices

Why does the Enter key, which normally behaves like a click on the Continue (submit) button, correctly call the validation routine but then incorrectly submit the page whereas the click on the Continue (submit) button works as expected?

monte96
Nov 8th, 2000, 06:39 PM
Post your validation routine, and the tags that call it.

Tough to answer something like this without seeing the code, however, be aware that enter by default submits a form unless you are trapping it..

dadames
Nov 9th, 2000, 07:29 AM
The validation is not my code but I'll get a copy.

Thanks for you reply.

sterrace
Jan 18th, 2001, 04:09 PM
I have a similar problem. Pressing the <Enter> key to fire the OK button does not call the LostFocus or Validate events on a text box that was in the process of being edited.

Manually hitting the OK button causes validation. The OK button is set as the default. Is there any way around this problem without writing extra code on the OK_click event to validate all text boxes on the form?

Jan 19th, 2001, 07:00 AM
If you are sure that the end user's browser is nice with it's javascript suppport then you could make the submit button a normal button (type="button" not type="submit") then move your validation code off the onBlur event and onto the onClick event of the button...so the button's code would be something like:


...
<script language="javascript" type="text/css">

function ValidatetxtRemote() {

if (txtRemote.Value > 40000) {
alert('The value must be no greater than 40000!');
txtRemote.Value = 0;
}
else
{
frmForm.Submit();
}

}

</script>
</head>
<body background="/images/bground.gif" bgcolor="#ffffff" text="#000000" marginheight="0" topmargin="0">
<form method="post" action="<%=Request.ServerVariables("SCRIPT_NAME") %>" id="frmForm">
<input type="text" name="txtRemote" id="txtRemote">
<input type="button" value="Submit" onClick="javascript:ValidatetxtRemote()">
</form>
...

Sorry if some of the syntax isn't quite right...I've been doing a lot of PHP recently so my javascript might be a little rusty... I'm not sure if the "if" statement is quite right. :rolleyes:

Jan 19th, 2001, 07:02 AM
Incidentally I think pressing enter bypasses the onBlur event because the focus isn't actually taken away from the text box when you press enter...IE just runs the code behind the enter button directly.