www.webdeveloper.com
Results 1 to 2 of 2

Thread: Trying to match submit and onblur functionality

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Question Trying to match submit and onblur functionality

    I have a form with a single field and as part of my learning, I created a simple functionality using the blur function of jquery - which happens to work as expected. However, the form resets after I hit the submit button. I want to modify such that blur function code works on submit as well. I presume this must be pretty simple, but I just don't have the knowledge to do and something I could not figure out using google searches. Can somebody provide any tips/suggestions? Not sure if this forum allows posting HTML code, but I will try below. In the code below, I would like to continue increase the value of intGuesseSoFar during each try of the user (when it is not blah). If it blah, I want to reset the form.
    Thanks all.

    <!DOCTYPE html>
    <head>
    <title>WD - Assignment1</title>
    <link rel="stylesheet" type="text/css" href="wdtest.css" />
    <link rel="stylesheet" type="text/css" href="RMSforms-v0.5.css" />
    <script src="jquery.js"><script>
    <script src="app.js"></script>
    <script>
    nIncorectGuesses = 0;
    $(document).ready(function() {
    console.log("in ready function - " + nIncorectGuesses );
    $('#yourGuess').blur(function()
    {
    console.log("in blur function - " + nIncorectGuesses);
    if ($('#yourGuess').val().toLowerCase() != "blah") {
    console.log("in if condition - " + nIncorectGuesses);
    nIncorectGuesses++;
    $('#intGuesseSoFar').val(nIncorectGuesses);
    }
    });
    });
    </script>
    </head>
    <body>
    <div class="formConatiner">
    <h2>Test</h2>
    <form id = "testform">
    <fieldset>
    <ul class="form">
    <li class="leftNote"><label>Your Guess</label><input type="text" id="yourGuess" name ="yourGuess" /></li>
    </ul>
    <p>Number of guesses so far: <output id="intGuesseSoFar" name = "intGuesseSoFar"/></p>
    <input type="submit" value="Play" id='play';">
    </fieldset>
    </form>
    </div>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,372
    Try asking in the JQuery (JavaScript Frameworks) forum.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles