SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Auto submit form onblur when input field says PASS

    I need to know how to make a form auto submit after I tab out of it or lose any focus on it if it says what I want it to say (the word PASS). My initial thought is to use onblur="submitform();" but how do I make it only do that if it ALSO says the word PASS?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by simplycomplex85 View Post
    I need to know how to make a form auto submit after I tab out of it or lose any focus on it if it says what I want it to say (the word PASS). My initial thought is to use onblur="submitform();" but how do I make it only do that if it ALSO says the word PASS?
    Here is a form with a field in it.

    HTML Code:
    <form id="autopass">
        <p><input name="codeword"></p>
    </form>
    Attach an onblur event to the field:

    Code javascript:
    var form = document.getElementById('autopass'),
        field = form.elements.codeword;
     
    field.onblur = fieldBlurHandler;

    The fieldBlurHandler function is where you can check that its value matches. If it matches, then you can submit the form.

    Code javascript:
    function fieldBlurHandler() {
        if (this.value === 'PASS') {
            this.form.submit();
        }
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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