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

x
?
Solved

JavaScript to validate form for less than 10 characters

Posted on 2011-03-01
2
Medium Priority
?
249 Views
Last Modified: 2012-05-11
The JavaScript below works when the form is empty but I also want to check another condition if the value is less then 10. How do I do this with my example code?
<SCRIPT language="JavaScript">
function validateForm(form) {

   if (form.TITLE.value == "") {
      alert("Your title is empty.");
      return false
   }
   
   if (form.STORY_BODY.value == "") {
      alert("Please enter story.");
      return false
   }

   return true
}

</SCRIPT>

Open in new window

0
Comment
Question by:Qsorb
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 35013806
Use : form.STORY_BODY.value.length < 10
<SCRIPT language="JavaScript">
function validateForm(form) {

   if (form.TITLE.value == "") {
      alert("Your title is empty.");
      return false
   }
   
   if (form.STORY_BODY.value.length < 10) {
      alert("Please enter story.");
      return false
   }

   return true
}

</SCRIPT>

Open in new window

0
 

Author Closing Comment

by:Qsorb
ID: 35013822
Great. And thanks. That was certainly quick.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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.
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

885 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