The number of characters in the text field in the Twitter format with a built-in notification

I would like the text field character to โ€œcountโ€, which will increment the counter as a user type and display a text warning when the user crosses the desired character, but still allows the user to continue typing.

Thanx in advance!

+4
source share
2 answers

If you want to flip your own

HTML

<div> Type text here: <input type="text" id="txt" /> </div> <div id="warning" style="color: red; display: none"> Sorry, too much text. </div> <br> <input type="text" id="counter" disabled="disabled" value="0"/> 

Script

 $("#txt").keyup(function () { var i = $("#txt").val().length; $("#counter").val(i); if (i > 10) { $("#warning").show() } else { $("#warning").hide() } }); 

Jsfiddle here

+8
source

All Articles