Created
July 13, 2014 16:37
-
-
Save muffycompo/7b7d293e4c3dbd0b47a5 to your computer and use it in GitHub Desktop.
jQuery Textarea Character Counter
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
$(document).ready(function(){ | |
// Message counter | |
var message_start = 0; | |
var sms_start = 1; | |
$('#message_count').html(message_start); | |
$('#sms_count').html(sms_start); | |
$('#sms_message').keyup(function() { | |
var character_count = $('#sms_message').val().length; | |
var character_max = message_start + character_count; | |
$('#message_count').html(character_max); | |
if(character_count >= 160){ | |
var sms_page_count = Math.floor(character_count / 160); | |
if(sms_page_count === 0){ | |
sms_start = 1; | |
} else if(sms_page_count === 1){ | |
sms_start = 2; | |
} else if(sms_page_count === 2){ | |
sms_start = 3; | |
} else if(sms_page_count === 3){ | |
sms_start = 4; | |
} else if(sms_page_count === 4){ | |
sms_start = 5; | |
} else if(sms_page_count === 5){ | |
sms_start = 6; | |
} | |
$('#sms_count').html(sms_start); | |
} else { | |
sms_start = 1; | |
$('#sms_count').html(sms_start); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment