poe Posted September 14, 2007 Share Posted September 14, 2007 i have 3 radio buttons, each one will set the max number of words that can be inputted into the "desc" form textarea. i think i am almost there except when the person reaches the limit of words, you are still able to type spaces. <script language="JavaScript"> function cntWd(field,wordcount,balance,maxwd){ var y = field.value; var max = maxwd.value; var r = 0; a = y.replace(/\s/g,' '); a = a.split(' '); for (z=0; z<a.length; z++) {if (a[z].length > 0) r++;} var bal = maxwd.value - wordcount.value; if(max < r) { field.value = field.value.substring(0, field.value.length-1); } else { wordcount.value = r; balance.value = maxwd.value - wordcount.value; } } </script> and the form is: <table border=0> <tr><td> <form name="myform"> <input type=radio name=adplan value=20 onClick="setMax(this,document.myform.maxwd)">20 word max<br> <input type=radio name=adplan value=10 onClick="setMax(this,document.myform.maxwd)">10 word max<br> <input type=radio name=adplan value=5 onClick="setMax(this,document.myform.maxwd)">5 word max<br> <textarea rows="6" name="desc" cols="30" onkeyup="cntWd(this,document.myform.wordcount,document.myform.balance,document.myform.maxwd)"></textarea><br> <input type="text" name="wordcount" value="0" size="5" onkeyup="cntWd(document.myform.desc,this,document.myform.balance,document.myform.maxwd)"> : total words<br> <input type="text" name="balance" value="0" size="5"> : balance<br> <input type="text" name="maxwd" size="5"> : Max<br> </form> </td></tr> </table> </center> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.