how to call jscript onFormSubmit() with eventArgs e (classic asp)
If I have the following jscript code on a classic asp page, how do I supply the "eventArgs e" in the call so it will be available here in the jscript? The "eventArgs e" being an asp.net term, I am not sure what is used here.
response.write "<script type='text/j开发者_JAVA技巧avascript'>"
response.write "function onFormSubmit(e)"
response.write "{ var keycode;"
response.write "if(window.event) keycode = window.event.keyCode;"
response.write "else if (e) keycode = e.which;"
response.write "else return true;"
response.write "if (keycode == 13)"
response.write "{ myform.submit();"
response.write "return false; }"
response.write "else return true; }"
response.write " </script>"
And the call looks like this:
response.write "<form name='myform' action='logon' method='post' onSubmit='onFormSubmit()'>"
Thank you, Jim
Edit: let's go full solution. Does this work for you?
<%@ Language=VBScript %>
<html>
<head>
<title>test</title>
<script type="text/javascript">
function submitIfEnter(e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
var f = document.myform;
f.action.value = "Forum Logon";
f.submit();
}
}
</script>
</head>
<body>
<%
if request.form("action") <> "" then
response.write "submit value = " + request.form("bsubmit") + "<br />"
response.write "action value = " + request.form("action") + "<br />"
else
%>
<form method="post" name="myform">
<input type="text" onkeydown="submitIfEnter(event);"/>
<input type='hidden' name='action' value='action1'>
<input type='submit' name='bsubmit' value='Guest Register'>
<input type='submit' name='bsubmit' value='Forum Logon'>
</form>
<%
end if
%>
</body>
</html>
精彩评论