|
-
Jan 22nd, 2011, 06:19 AM
#1
Thread Starter
Frenzied Member
textbox characters
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>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jan 22nd, 2011, 11:42 AM
#2
Fanatic Member
Re: textbox characters
PHP Code:
$bio= $_POST['bio'];
$text = substr($bio,0,200);
echo $text;
this will only display 200 characters, of what has been submitted.
to make the textarea only allow 200 characters, you should try javascript.
-
Jan 22nd, 2011, 01:37 PM
#3
Re: textbox characters
You'd want to accomplish this using JavaScript, otherwise the user has no way of knowing when they reach the character limit.
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)
}
}
then, just modify your <textarea> to have an ID of 'bio':
HTML Code:
<textarea name="bio" id="bio" cols="35" rows="5"></textarea>
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.
Last edited by kows; Jan 22nd, 2011 at 01:43 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|