PDA

View Full Version : limiting characters in textarea without php/javascript


mrjameer
10-03-2006, 12:39 AM
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

mlseim
10-03-2006, 02:51 AM
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.

_Aerospace_Eng_
10-03-2006, 05:07 AM
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.

Fumigator
10-03-2006, 05:28 AM
"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.

<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>

mrjameer
10-03-2006, 09:51 PM
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

Fumigator
10-04-2006, 12:20 AM
It's zero based :p