Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maximum length of a text field

Status
Not open for further replies.

cwolgamott

Programmer
May 29, 2002
69
US
Hello. :) I am creating a web page and I would like to set a maximum length of a text field so that the user can only enter the number of characters that I allow, and then does not let them enter anymore after that maximum has been hit. I have tried setting the Char Width and Num lines, but this does not stop the user from entering more than the limit. I would greatly appreciate any suggestions or help. :) Thank you.
 
Try this

Code:
<input name=&quot;yourname&quot; type=&quot;text&quot; maxlength=&quot;10&quot;>
The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Thank you so much for your reply. :) I greatly appreciate it. I have another question though. How can I get that to work with a multiple line text area? I would greatly appreciate any suggestions that you might have. :) Thanks again. :)
 
Hmmmmmmm..

Good one

You might want to do some javascript form validation. But I think that will only work after the user tries to submit the form, it wont stop them entering more than a set number of chars.

I will have a look for a script to do something for you.

Cheech The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
OK here goes.. this checks to see if there is more than 100 chars in a text area before submitting a form

insert this into the
Code:
<head>
section

Code:
<!--
function validateform()
{
if (document.yourformname.yourtextareaname.value>&quot;100&quot;)
{
window.alert (&quot;The Text area has over 100 characters in!!&quot;)
return false;
}
}
//-->
</script>

and your form tag should have this in:

Code:
onSubmit=&quot;return validateform( this.form )&quot;
The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Thank you so much for all of your help. :) I greatly appreciate it. :)
 
I guess that is why there is a Click here to mark this post as a helpful or expert post [poke] The secret of life is honesty and fair dealing. If you can fake that, you've got it made.
Groucho Marx (1895-1977)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top