Wednesday, 1 October 2014

check input field length in jquery?

check input field length in jquery?

check input field length in jquery?
click on this
<a href="test">test</a>

<div id="selector"></div>
<input type="text" id="textbox"/>

<div id="selectorSize"></div>
<div id="name"></div>

==================================
JQuery script is
==================================
jQuery(function () {
    $('a').click(function (e) {
        e.preventDefault();
        var name = $(this).text();
        var myLength = $("#textbox").val();
        $("#selectorSize").text(myLength.length);
       
        if (myLength.length <= 6) {
              $("#name").text("ERR");
             $("#name").addClass("error");
         }
       
        $("#selector").text(name);
        $("#textbox").val(name);
    });
});
============================================

View Demo Here

No comments:

Post a Comment