Monday, 26 December 2016

Jquery character and Message count textarea




JS

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#messageValue").keyup(function(){
//$("#count").text($(this).val().length);
var wordCount = $(this).val().length;
var messagePart = document.getElementById('message_part');
$("#characterCount").text(wordCount);
//alert(wordCount);
if (wordCount > 159) {
var z = wordCount / 160;
z = Math.floor(z);
z = z + 1; 
} else {
var z = 1;
}
messagePart.innerHTML = z;
});
});
</script>


HTML

<textarea name="message" id="messageValue" rows="10" placeholder="Message" required></textarea>
<div><span id="characterCount" style="color:#F00;">0</span> Characters in text Box. 
Send this Message in <span id="message_part" style="color:#F00;">1</span> Part                          
Jquery character and Message count textarea



No comments:

Post a Comment