Return to Snippet

Revision: 31890
at November 11, 2010 12:26 by housecor


Updated Code
$('textarea').keyup(function () {
	var max = 4000;
	if ($(this).val().length > max) {
		$(this).val($(this).val().substr(0, max));
	}

	$(this).parent().find('.chars_remaining').html('You have ' + (max - $(this).val().length) + ' characters remaining').show();
});

//hide chars remaining count on blur
$('textarea').blur(function () { $('.chars_remaining').fadeOut('fast'); });

//and in the front end:
<span class="chars_remaining ui-state-highlight"></span>

Revision: 31889
at November 11, 2010 12:25 by housecor


Updated Code
$('textarea').keyup(function () {
		var max = 4000;
		if ($(this).val().length > max) {
			$(this).val($(this).val().substr(0, max));
		}

		$(this).parent().find('.chars_remaining').html('You have ' + (max - $(this).val().length) + ' characters remaining').show();
	});

	//hide chars remaining count on blur
	$('textarea').blur(function () { $('.chars_remaining').fadeOut('fast'); });

//and in the front end:
<span class="chars_remaining ui-state-highlight"></span>

Revision: 31888
at September 15, 2010 11:32 by housecor


Updated Code
$('textarea').keyup(function () {
		var max = 4000;
		if ($(this).val().length > max) {
			$(this).val($(this).val().substr(0, max));
		}

		$(this).parent().find('.chars_remaining').html('You have ' + (max - $(this).val().length) + ' characters remaining').show();
	});

	//hide chars remaining count on blur
	$('textarea').blur(function () { $('.chars_remaining').fadeOut('fast'); });

Revision: 31887
at September 15, 2010 11:22 by housecor


Initial Code
$('textarea').keyup(function () {
		var max = 4000;
		if ($(this).val().length > max) {
			$(this).val($(this).val().substr(0, max));
		}

		$(this).parent().find('.chars_remaining').html('You have ' + (max - $(this).val().length) + ' characters remaining');
	});

Initial URL

                                

Initial Description
Just be sure to slap the div for the chars left message within the same div/p as the textarea so the dom walk works.

Initial Title
Enforce maxlength for all textareas on page

Initial Tags
javascript, jquery

Initial Language
JavaScript