-
I am confused by something that's happening with some asp pages I am editing.
I effectively just have a search box "frmSearch" and a button "btnSearch" which submits the form.
When I press {ENTER} in "frmSearch" the form is submitted. Why? How can I stop this happening?
Thanks!
-
I think this is the default behavior for a form when you have a submit button. Perhaps, change the type to button and code an onClick event.
-
Yeah- I meant, when I press {ENTER} in the input box, not press the button.
The button is already a "button" not a "submit".
I have found a workaround for this behaviour though:
Check if they've pressed the {ENTER} key (keycode 13) then cancel the event if necessary.
Code:
sub frmSearch_onkeypress()
if document.theform.frmSearch.value = "" and window.event.keyCode = 13 then '{enter} key pressed with no data in input box
msgbox "You have not entered a search string!",0
window.event.returnValue = false
end if
if window.event.keyCode = 13 then
window.event.returnValue = false
end if
end sub