Validate form in coldfusion using java script

Posted on 2011-10-27
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(,'You need to enter an Email Address.');
		if(formSubmit) {
			formIsEmail(,'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
    LVL 51

    Expert Comment

    What is it doing wrong or not doing correctly?

    Author Comment

    Does nothing I don't get error message and its not validating.
    LVL 51

    Accepted Solution

    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 ??

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them ( . I did keep the main js functions but made sever…
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 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

    23 Experts available now in Live!

    Get 1:1 Help Now