Monday, 18 July 2011

Twitter style input validation

 Maximum size allowed is 140. The number of remaining characters
are displayed live.

index.html
----------
<body>
        Message:<br/><textarea rows="10" cols="150" id="tweet">Message</textarea>
        <div id="msg"></div>
        <script type="text/javascript" src="jsfunc.js"></script>
    </body>
jsfunc.js
---------
var max_size=140;
$('#tweet').keyup(function(){
   var tweet_length=$(this).val().length; //.val() retrieves the message//.length length of the message// 
   var tweet_remain= max_size - tweet_length;
   $('#msg').html("<b>You have "+ tweet_remain + " characters remaining</b>");
});

No comments:

Post a Comment