Solved

Creating a Maxlength for Multiple Textareas

Posted on 2008-10-27
2
238 Views
Last Modified: 2012-05-05
I have a couple text boxes in a form.  They both require a different amount of lengths.  It reads the one javascript to check it, but not for the second textarea.  How do I get both of them to work.

Here is my Code:

<script language="javascript" type="text/javascript">
<!--
function validate() {
      maxlength=1000;
      if(document.myForm.ldesc.value.length>=maxlength) {
            alert('Your Long Description must be 1000 characters or less');
            document.myForm.ldesc.focus();
            return false;
      } else {
            return true;
      }
}

function validate1() {
      maxlength=250;
      if(document.myForm.bdesc.value.length>=maxlength) {
            alert('Your Brief Description must be 250 characters or less');
            document.myForm.bdesc.focus();
            return false;
      } else {
            return true;
      }
}
//-->
</script>

Here is the form Action:
<cfform name="myForm" action="submitMod2.cfm" method="post" enctype="multipart/form-data" onsubmit="return validate(); return validate1();" >
0
Comment
Question by:GreatPlains
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 125 total points
ID: 22813698
Why don't you combine the two functions?




<script language="javascript" type="text/javascript">

<!--

function validate() {

      maxlength=1000;

      if(document.myForm.ldesc.value.length>=maxlength) {

            alert('Your Long Description must be 1000 characters or less');

            document.myForm.ldesc.focus();

            return false;      

      }
 

 maxlength=250;

      if(document.myForm.bdesc.value.length>=maxlength) {

            alert('Your Brief Description must be 250 characters or less');

            document.myForm.bdesc.focus();

            return false;            

      }
 

return true;

}

//-->

</script> 

Open in new window

0
 

Author Comment

by:GreatPlains
ID: 22813737
I had tried that before and couldn't get it working, but It is now.

Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now