How do i get my textbox to only accept say 200 characters in it and no more i use this code.
Code:<tr>
<td>Bio/About:</td>
<td><textarea name='bio' cols='35' rows='5'></textarea></td>
</tr>
Printable View
How do i get my textbox to only accept say 200 characters in it and no more i use this code.
Code:<tr>
<td>Bio/About:</td>
<td><textarea name='bio' cols='35' rows='5'></textarea></td>
</tr>
this will only display 200 characters, of what has been submitted.PHP Code:$bio= $_POST['bio'];
$text = substr($bio,0,200);
echo $text;
to make the textarea only allow 200 characters, you should try javascript.
You'd want to accomplish this using JavaScript, otherwise the user has no way of knowing when they reach the character limit.
then, just modify your <textarea> to have an ID of 'bio':Code:window.onload = function(){
document.getElementById("bio").onkeypress = function(){
// Don't let them continue typing if they're over the 200 character limit
return !(this.value.length > 200)
}
}
However, just as a side note, this won't stop someone from pasting more than 200 characters into the textbox. You may want to look into having it auto-trim the textbox after losing focus or something. Then, of course you should trim the string on the server side as well.HTML Code:<textarea name="bio" id="bio" cols="35" rows="5"></textarea>