SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    why not work this code?

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        
        <head>
            <style>
                    .not_ok {
                    background: url(notok.gif);
                    width: 32px;
                    height: 28px;
                    }
            </style>
            <script src="jquery-1.6.min.js"></script>
            <script>
                $(document).ready(function() {
                    $("#input_submit").click(function() {
                        var usr = $("#input_username").val();
                        if (usr.length >= 3) {
                            $("#status").html('Checking availability...');
                        } else {
                            $("#status").html('<div class="not_ok"></div>');
                        }
                    });
                });
            </script>
        </head>
        
        <body>
            <div id="status"></div>
            <form method="post" action="">
                <p>
                    <input type="text" name="name" />
                </p>
                <p>
                    <input class="submit" type="submit" value="Submit" id="input_submit" />
                </p>
            </form>
        </body>
    
    </html>

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The field with the id of input_username doesn't exist, simply add id="input_username" to the field with the name of name. Also your form will submit no matter what so you will need to update your code so it prevents the default action like the example below...

    Code JavaScript:
    $(function() {
        $("#input_submit").click(function(e) {
            e.preventDefault();
     
            // Your code here...
        });
    });

  3. #3
    Non-Member
    Join Date
    Nov 2010
    Posts
    220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks


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
  •