Results 1 to 3 of 3

Thread: onBlur

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    18

    onBlur

    on my html page, I have one text box and one submit button.Text box has validation routine on its onBlur event. When I enter invalid text in text button and try to click submit button validation routine works fine and alert message is shown and form is not submitted. Submit button can also be called by Alt + G (I have set up code for hotkeys using javascript), but this time onBlur event is not invoked as focus remains on the text box.

    how can I stop form from being submitted when user presses Alt+G with invalid text in text box. The page may contain multiple text boxes with onBlur events.

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Location
    Sweden, Sthlm
    Posts
    112
    hi!

    Insted of using a submit button you can use a normalbutton and
    onthe mousedown event you call the validate function and
    you also call this function from the Alt+G press

    function validate()
    {
    valid = isvalid()

    if(valid == true){
    document.form.submit
    }
    }

  3. #3
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I would do it a little differently, and use the onsubmit event handler of the form. This way you don't need to bother manually calling the function, and you only need to declare it once, and it will work regardless of whether the user pressed enter, clicked the button or whatever:

    Code:
    <script type="text/javascript"><!--
      function validate(formElement) {
        //ALL YOUR VALIDATE STUFF HERE -
        // RETURN TRUE IF ALL IS OK
        if (formElement.txt.value != '') {
          return true;
        }
        //Only gets here if the form doesn't validate
        return false;
      }
    //--></script>
    <form action="page.php"
     onsubmit="return validate(this);"><p>
      <input name="txt" /><input accesskey="G" type="submit" />
    </p></form>

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