Web Analytics Made Easy -
StatCounter limiting characters in textarea without php/javascript - CodingForum

Announcement

Collapse
No announcement yet.

limiting characters in textarea without php/javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • limiting characters in textarea without php/javascript

    hi,

    i want to create a textarea in which the user can input 100 characters only.he canot able to input more than 100.i want to do this with out using php/javascript.is it possible.your help will be appreciated

    thanks

    mrjameer

  • #2
    Only other possibility would be Flash.

    You could check the length with PHP, but only after the
    form was submitted, which would be too late.

    Comment


    • #3
      The best you can do without any scripting is maxlength="100" inside the open textarea tag though someone can change that easily if they wanted to.
      ||||If you are getting paid to do a job, don't ask for help on it!||||

      Comment


      • #4
        "maxlength" doesn't work on <textarea> tags, only <input type="text"> tags.

        Here's a Javascript one I use... you did say you wanted to avoid using Javascript but I don't think there's any way to do that.
        Code:
        <textarea name="addNewsBox" class="areaentry" onkeydown="return maxChars(this, 2000);"><?php echo $_POST['addNewsBox']; ?></textarea><br />
        <div id="countDisp">&nbsp;</div> 
        
        <script type="text/javascript">
        
        function maxChars(ta, count) {
        	document.getElementById('countDisp').innerHTML = 'Character count: ' + ta.value.length;
        	if (ta.value.length >= count) {
        		ta.value = ta.value.substring(0, (count - 1));
        		document.getElementById('countDisp').innerHTML = 'Maximumum character count reached!';
        	} else {
        		document.getElementById('countDisp').innerHTML = 'Character count: ' + ta.value.length + ' out of ' + count;
        	}
        	
        	return (ta.value.length < count);
        }
        </script>

        Comment


        • #5
          hi fumigator,

          i already tested your code but it is not counting the first character which i entered in textarea it is counting from second character.


          thanks
          mrjameer

          Comment


          • #6
            It's zero based

            Comment

            Working...
            X