PHP Web Developer.

สิงหาคม 15, 2012

jQuery: Textbox Validation and the blur() Event

Filed under: Javascript & jquery — Prajak @ 6:04 pm

<b>Username:</b> <i>Username must be at least 4 characters in length</i>
<input type=”text” id=”txt_username” name=”username”>
<span id=”username_warning” style=”color:red”></span>
<b>Password:</b> <i>Password must be at least 6 characters in length</i>
<br><input type=”password” id=”txt_password” name=”password”>
<span id=”password_warning” style=”color:red”></span>

 

$(document).ready(function(){ 
    $("#txt_username").blur(function() 
    { 
        var username_length; 
 
        username_length = $("#txt_username").val().length; 
        $("#username_warning").empty(); 
 
        if (username_length < 4) 
            $("#username_warning").append("Username is too short"); 
    }); 
 
    $("#txt_password").blur(function() 
    { 
        var password_length; 
 
        password_length = $("#txt_password").val().length; 
        $("#password_warning").empty(); 
 
        if (password_length < 6) 
            $("#password_warning").append("Password is too short"); 
    }); 
}); 

ให้ความเห็น »

ยังไม่มีความเห็น

RSS feed for comments on this post. TrackBack URI

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

สร้างเว็บไซต์หรือบล็อกฟรีที่ WordPress.com.

%d bloggers like this: