Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating a Maxlength for Multiple Textareas

Posted on 2008-10-27
2
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

722 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