Dynamically displays the number of words that can be entered

  • 2020-03-30 02:32:22
  • OfStack

 
<input name="title" type="text" size="50" value="{$p.title}" maxlength="15" onkeyup="javascript:setShowLength(this, 15, 'cost_tpl_title_length');"><span class="red" id="cost_tpl_title_length"> You can also type in 15 Number of words </span> 

js :
 
function setShowLength(obj, maxlength, id) 
{ 
var rem = maxlength - obj.value.length; 
var wid = id; 
if (rem < 0){ 
rem = 0; 
} 
document.getElementById(wid).innerHTML = " You can also type in " + rem + " Number of words "; 
} 

Related articles: