Search Google

Monday, 11 August 2014

learn javascript word counter in javascript


 Thumbnail Slider in js

http://www.javascriptkit.com/script/script2/thumbslider.shtml


http://www.javascriptkit.com/script/script2/amazonsidebarmenu.shtml


 http://www.javascriptkit.com/cutpastejava.shtml
......................................................................

 http://jsfiddle.net/deepumohanp/jZeKu/
counter = function() {
    var value = $('#text').val();

    if (value.length == 0) {
        $('#wordCount').html(0);
        $('#totalChars').html(0);
        $('#charCount').html(0);
        $('#charCountNoSpace').html(0);
        return;
    }

    var regex = /\s+/gi;
    var wordCount = value.trim().replace(regex, ' ').split(' ').length;
    var totalChars = value.length;
    var charCount = value.trim().length;
    var charCountNoSpace = value.replace(regex, '').length;

    $('#wordCount').html(wordCount);
    $('#totalChars').html(totalChars);
    $('#charCount').html(charCount);
    $('#charCountNoSpace').html(charCountNoSpace);
};

$(document).ready(function() {
    $('#count').click(counter);
    $('#text').change(counter);
    $('#text').keydown(counter);
    $('#text').keypress(counter);
    $('#text').keyup(counter);
    $('#text').blur(counter);
    $('#text').focus(counter);
});

No comments:

Post a Comment