PhpxZ Posted July 8, 2010 Share Posted July 8, 2010 How to Limit number of character in each line in textarea Let say script should allow maximum 4 rows and should allow 8 character in each line. Also If character reached the limit then it should move to next line. its will look like this: 12345678 90123456 78901234 this is my code what i need to add <textarea name="text" cols="76" rows="15" lang="lt"></textarea> Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/ Share on other sites More sharing options...
haku Posted July 8, 2010 Share Posted July 8, 2010 You can't do that purely through HTML. You could do it with javascript, but anyone who turns it off would be able to bypass it. Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/#findComment-1082970 Share on other sites More sharing options...
PhpxZ Posted July 8, 2010 Author Share Posted July 8, 2010 and how can i do it with javascript? Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/#findComment-1082975 Share on other sites More sharing options...
PhpxZ Posted July 8, 2010 Author Share Posted July 8, 2010 and how can i do it with javascript? Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/#findComment-1083186 Share on other sites More sharing options...
PhpxZ Posted July 9, 2010 Author Share Posted July 9, 2010 Anyone? :-\ Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/#findComment-1083479 Share on other sites More sharing options...
radar Posted July 12, 2010 Share Posted July 12, 2010 You could do something like this: <textarea cols="20" rows="5" id="t1" onkeyup="testchar();"></textarea> <script type="text/javascript"> <!-- function testchar(){ var lastpos = 0; var numlines = 1; var lineend = 20; var linelength = 20; var my_string = document.getElementById("t1").value for(i=0;i<my_string.length;i++){ if(i>lineend){ numlines= parseInt(numlines) + parseInt('1'); lineend= parseInt(lastpos) + parseInt(linelength) + parseInt('1'); lastpos=i; } if(my_string.charAt(i)==' '){ lastpos = i; //alert('blank found at' + my_string.charAt(i)) } var myRegExp = /\n/ if (myRegExp.test(my_string.charAt(i))) { alert('hello') numlines= parseInt(numlines) + parseInt('1'); lineend= parseInt(lineend) + parseInt(linelength) + parseInt('1'); lastpos=parseInt(lineend) - parseInt(linelength); } } if(numlines > 5){ alert('You are beyond the number of lines allowed, please revist your text'); // alert('number of lines' + numlines); // alert('last position of a space' + lastpos); // alert('current line end value' + lineend); // alert(i); } } //--> </script> Link to comment https://forums.phpfreaks.com/topic/207121-how-can-i-limit-maximum-chars-per-row/#findComment-1085014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.