I want to make a command button default, meaning that when the user presses the enter button, the button code is executed. How do I do that?
Printable View
I want to make a command button default, meaning that when the user presses the enter button, the button code is executed. How do I do that?
In HTML? If you have a submit button that becomes the default button. If you have more then one form then submit button for the active form (the form which has focus) will be executed.Quote:
Originally Posted by GamerMax5
If its not HTML you are talking about, then please clarify.
In VBScript.
I am sorry, i am kinda lost. Can you explain what exactly you are trying to do?Quote:
Originally Posted by GamerMax5
He wants to detect the [ENTER] key and then submit a form -- no matter what one the page has focus...
so something like:
I know in there somewhere you have to pass the event data, but I don't know where. Also I'm not sure if "document.MyForm.submit" is exactly correct, but it should point you down the right path.Code:<head>
<script language="VBScript">
Function handleKeyPress
If pressedKey = 13 Then document.MyForm.submit
End Function
</script>
<body onKeyPress="handleKeyPress()">
Quote:
Originally Posted by Disiance
Well then the following should be what exactly he is looking for. Note it will only work in IE.
HTML Code:<html>
<head>
<script language="VBScript">
Function handleKeyPress
if (window.event.keyCode =13) then
myfunction
end if
End Function
function myFunction
msgbox "You have pressed Enter Key"
'Your default code goes here......
end function
</script>
<body onKeyPress="handleKeyPress()">
<form>
<input type=text>
<br>
<input type=text>
<br>
<input type=text>
<select>
<option>hello</option>
</select>
<body
</html>