Results 1 to 6 of 6

Thread: Enter Key problem

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Florida
    Posts
    45
    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?
    If I could only remember my name...

  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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..
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Florida
    Posts
    45

    Enter key problem

    The validation is not my code but I'll get a copy.

    Thanks for you reply.
    If I could only remember my name...

  4. #4
    New Member
    Join Date
    Jan 2001
    Posts
    3

    Enter key does not cause validation

    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?

  5. #5
    Guest
    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:

    Code:
    ...
        <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.

  6. #6
    Guest
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width