Validate form in coldfusion using java script

Posted on 2011-10-27
Medium Priority
Last Modified: 2012-05-12
I need help getting this form to validate.  Can someone please take a look at this code and see what I'm doing wrong.

Thank you,

Ken D.
                              function submitForm(theForm) {
		// validate firstName
		formRequired(theForm.firstName,'You need to enter a First Name.');
		formIsAlphaNumeric(theForm.firstName,'Please enter a valid First Name');
		//validate lastName
		formRequired(theForm.lastName,'You need to enter a Last Name.');
		formIsAlphaNumeric(theForm.lastName,'Please enter a valid Last Name');
		//validate userName
		formRequired(theForm.userName,'You need to enter a Username.');
		formIsAlphaNumeric(theForm.userName,'Please enter a valid Username');
		// validate password and vpassword
		formRequired(theForm.password,'You need to enter a Password.');
		formIsAlphaNumeric(theForm.password,'Please enter a valid Password.');
		formRequired(theForm.vPassword,'You need to verify your Password.');
		formIsAlphaNumeric(theForm.vPassword,'Please enter a valid verification Password.');
		formRequired(theForm.userCaptcha,'Please enter sign up code.');
		if(formSubmit) {
			formIsSame(theForm.vPassword,theForm.password,'Your password and verifictation password do not match.');
		// validate email
		formRequired(theForm.email,'You need to enter an Email Address.');
		if(formSubmit) {
			formIsEmail(theForm.email,'Please enter a valid Email Address.');
		if( formSubmit)
			if( theForm.userCaptcha.value !== theForm.hiddenCaptcha.value )
				throwError(theForm.userCaptcha,'Signup Code is incorrect');
				//generate a new captcha code

		if(formSubmit) {
			return true;
		} else {
			return false;

<form action="" method="post" name="newMember" onSubmit="return submitForm(this)">
              <table width="555" border="0" cellspacing="9" cellpadding="0">
                  <td width="84">First Name:</td>
                  <td width="172"><input name="firstName"<cfif isDefined("form.firstName")> value="<cfoutput>#form.firstName#</cfoutput>"</cfif> type="text" tabindex="1" title="First Name" size="25" maxlength="50" /></td>
                  <td width="90">Last Name:</td>
                  <td width="164"><input name="lastName" type="text" tabindex="2" title="Last Name" size="25" maxlength="50" /></td>
                  <td>User Name:</td>
                  <td><input name="userName" type="text" tabindex="3" title="Username" size="25" maxlength="50" /></td>
                  <td><input name="email" type="text" tabindex="4" title="Email" size="25" maxlength="50" /></td>
                  <td><input name="password" type="password" tabindex="5" title="Password" size="25" maxlength="15" /></td>
                  <td>Verify Password:</td>
                  <td><input name="vPassword" type="password" tabindex="6" title="Verify Password" size="25" maxlength="15" /></td>
                  <td>Business Name:</td>
                  <td colspan="3"><input name="businessName" type="text" id="businessName" tabindex="7" title="Business Name" size="73" maxlength="100" /></td>
                  <td>Address 1:</td>
                  <td colspan="3"><input name="streetAddress" type="text" tabindex="8" title="Street Address" size="73" maxlength="100" /></td>
                  <td>Address 2:</td>
                  <td colspan="3"><input name="streetAddress1" type="text" tabindex="9" title="Street Address" size="73" maxlength="100" /></td>
                  <td><input name="city" type="text" tabindex="10" title="City" size="25" maxlength="50" /></td>
                      <select name="state" id="state">
                        <option value="OH">OH</option>
                  <td><input name="phone" type="text" id="phone" size="25" tabindex="12"/></td>
                  <td>Zip Code:</td>
                  <td><span class="small">
                    <input name="postalCode" type="text" tabindex="13" title="Postal Code" size="25" maxlength="50" />
                  <td colspan="3">How did you hear about us:
                      <select name="marketing" id="marketing">
                        <option value="Referal">Referal</option>
                        <option value="Search Engine">Search Engine</option>
                        <option value="Brochure">Brochure</option>
                        <option value="Radio">News Paper</option>
                        <option value="Radio">Radio</option>
                        <option value="Magazine">Magazine</option>
                        <option value="Other">Other</option>
                  <td height="24" colspan="3">Signup Code:
                      <span style="font-weight:bold;color:navy;background-color:white;font-size: 18px" id="visibleCaptcha">
                  <td colspan="4">Enter Signup Code:
                    <input type="text" name="userCaptcha" id="userCaptcha" value=""/>
                    <br />
                    <strong>Letters are case sensative</strong></td>
                      <input type="hidden" name="hiddenCaptcha" id="hiddenCaptcha" value=""/>
                      <input name="Submit" type="submit" value="Join">
                      <a href="../../terms_of_use.cfm"></a></p></td>
                  <td><a href="../../terms_of_use.cfm">Terms of Service</a></td>

Open in new window

Question by:sonicimpulse
  • 2
LVL 52

Expert Comment

ID: 37038584
What is it doing wrong or not doing correctly?

Author Comment

ID: 37039435
Does nothing I don't get error message and its not validating.
LVL 52

Accepted Solution

_agx_ earned 2000 total points
ID: 37039501
The code references a bunch of other functions and variables. If you run it FF you'll see error messages because it can't find them. Where are you defining them?

             if(formSubmit) {   //<=== a variable ??

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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 is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month16 days, 7 hours left to enroll

850 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