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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting form to certain length

Status
Not open for further replies.

hallm

Programmer
Jun 11, 2000
159
US
We're using an html form that posts to an asp page to add or update our database.  How can I provide a full proof method that the field lenghts are limited.  In other words when the user presses submit something that will check for length and not let the user key in more than a certain amount of text.  Also, how can you require that a field not be left empty, (Not be able to submit until a field be completed.)
 
Depending on the field, some form options like text and file fields will use a &quot;MAXLENGTH&quot; option that will limit the amount of characters entered.<br><br>Or, you could write a script like:<br><br>&lt;script language=&quot;javascript&quot;&gt;<br>function checkLength() {<br>a = document.formname.fieldname.value<br>if (if a.length &gt; Xnumber) {<br>alert(&quot;please limit your entries to less than x char.&quot;)<br>}<br>}<br>&lt;/script&gt;<br>...<br>...<br>&lt;input type=&quot;text&quot; onBlur=&quot;checkLength();&quot;&gt;<br>...<br>...<br><br>This form will run the script to check the length of the entered text as soon as he choses something other than this text box and ask him to enter something shorter than whatever XNumber represents.<br><br>Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top