Solved

Creating a Maxlength for Multiple Textareas

Posted on 2008-10-27
2
237 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 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

18 Experts available now in Live!

Get 1:1 Help Now