downah Posted April 8, 2012 Share Posted April 8, 2012 Hi guys I have this script here, which counts the characters and lines, now currently though it still allows lines and characters to go into minus, but I would like it to also put up a warning box so it stops the user from being able to put in more text, could you help me out? javascript: function textCounter(theField,theCharCounter,theLineCounter,maxChars,maxLines,maxPerLine) { var strTemp = ""; var strLineCounter = 0; var strCharCounter = 0; for (var i = 0; i < theField.value.length; i++) { var strChar = theField.value.substring(i, i + 1); if (strChar == '\n') { strTemp += strChar; strCharCounter = 1; strLineCounter += 1; } else if (strCharCounter == maxPerLine) { strTemp += '\n' + strChar; strCharCounter = 1; strLineCounter += 1; } else { strTemp += strChar; strCharCounter ++; } } theCharCounter.value = maxChars - strTemp.length; theLineCounter.value = maxLines - strLineCounter; } and used in code: <textarea name="comment" cols="50" rows="10" wrap="VIRTUAL" onKeyUp="textCounter(theForm.comment,theForm.remChars,remLines,900,30,50);"></textarea> <br><input name=remChars type=text value="900" size=3 maxlength=3 readonly> characters left <br><input name=remLines type=text value="30" size=3 maxlength=3 readonly> lines left<br> Quote Link to comment https://forums.phpfreaks.com/topic/260569-max-lines-need-a-popup-box/ 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.