views:

360

answers:

1

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/javascript'>"
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

A: 

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>
Eduardo Molteni
Thanks, I shall try that out!
Jim
Ok, but I think this is submitting the form, not the button I want. The problem was not getting the form to submit on enter. I have two buttons, both with the same name but different values to I can tell on the code page which button was pressed. But the wrong button is triggered on enter due to it's placement on the page.
Jim
Edited answer to explain better
Eduardo Molteni
Ok that looks a little different than what I was doing. Thank you for the detail. I am really new to asp classic. Have only been working asp.net for one year. The asp has given me plenty of challenges. I will try this and advise of results.Thanks,Jim
Jim
================
Jim