Created
October 19, 2010 09:23
-
-
Save simme/633912 to your computer and use it in GitHub Desktop.
Count characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Character counter | |
$('#edit-field-tagline-0-value, #edit-body').keydown(function(event) { | |
var id = $(this).attr('id'); | |
var counter = $('label[for="' + id + '"]').children('span'); | |
if (!counter.length) { | |
$('label[for="' + id + '"]').append('<span></span>'); | |
counter = $('label[for="' + id + '"]').children('span'); | |
} | |
counter.text(' (Antal tecken: ' + $(this).val().length + ')'); | |
if ($(this).val().length > maxLength) { | |
if (event.keyCode !== 8) { | |
alert('Maxlängden för vald restaurangkategori är nådd.'); | |
return false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment