Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i have little knowledge on javascript, so can you tell me how i can make a word limit in this below textarea

<textarea name="notes" "rows="4" cols="40"></textarea>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
121 views
Welcome To Ask or Share your Answers For Others

1 Answer

use this function

<script>
     function textAreaCounter(field,cntfield,maxlimit) 
    {

     if (field.value.length > maxlimit) 
     field.value = field.value.substring(0, maxlimit); 
     else cntfield.value = maxlimit - field.value.length;
    }

</script>
<form name="frmlist" id="frmlist" method="post">
<div>
                <textarea rows="8" cols="70" name="description" id="description" onFocus="textAreaCounter(document.frmlist.description,document.frmlist.descriptionCount,1000)" onKeyDown="textAreaCounter(document.frmlist.description,document.frmlist.descriptionCount,1000)" onKeyUp="textAreaCounter(document.frmlist.description,document.frmlist.descriptionCount,1000)"></textarea>
                <br>
                <br>
                <em>Characters remaining:</em>
                <input type="text" name="descriptionCount" id="descriptionCount" readonly="" size="5" value="<?php if(isset($frmdata['descriptionCount'])){echo $frmdata['descriptionCount']; } else{ echo '1000'; }?>" >
            </div></form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...