Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Creating a Maxlength for Multiple Textareas

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
GreatPlains
Asked:
GreatPlains
1 Solution
 
Tomarse111Commented:
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
 
GreatPlainsAuthor Commented:
I had tried that before and couldn't get it working, but It is now.

Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now