Jump to content

[SOLVED] Trouble with a form validator!


unkwntech

Recommended Posts

This is my form validation function and the basic form, when I use this code I am getting the following error:

Uncaught SyntaxError: Unexpected token on line 41

I added a comment to line 41 to show where it is, what am I doing wrong.

                       ...SNIP...
<head>
                       ...SNIP...
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function validateForm()
{
	names = /[\w ]/i;
if(!$('firstName').val().match(names))
 {
 	//First name does not match the required format
	$('firstNameError').html() = 'You must enter your first name and it must only contain letters and spcaes!';
 }
if(!$('lastName').val().match(names))
 {
 	//Last name does not match the required format
	$('lastNameError').html() = 'You must enter your last name and it must only contain letters and spcaes!';
 }
if(!$('phoneNumber').val().match('/\(?[\d]{3}\)?[ -]?[\d]{3}[ -]?[\d]{4}/'))
 { //LINE 41
 	//Phone number does not match any acceptable format
	$('phoneNumber').html() = 'You must enter you full 10 digit phone number!';
 }
if($('time1').val() > $('time2')).val())
 {
 	//Start time cannnot be before the end time
	$('timeError').html() = 'The start time must not be after the end time';
 }
}
</script>
                       ...SNIP...
                              <p>If you'd like to get a quote fill out this simple form and we will get back to you as soon as posible.</p>
                              <form name="quote" method="post" action="quoteProcessor.php">
                              	<font color="red"><div id="firstNameError"></div></font>
                                <p>First Name            <input type="text" name="firstName" id="firstName">
                                </p>
                                <font color="red"><div id="lastNameError"></div></font>
                                <p>Last Name            <input type="text" name="lastName" id="lastName">
                                </p>
                                <font color="red"><div id="phoneNumberError"></div></font>
                                <p>Phone Number     
                                  <input type="text" name="phoneNumber" id="phoneNumber">
                                </p>
                                <font color="red"><div id="timeError"></div></font>
                                <p>Best Time to Call is between 
                                  <select name="time1" id="time1">
                                    <option value="7">7am</option>
                                                           ...SNIP...
                                    <option value="21">9pm</option>
                                  </select> 
                                  and 
                                  <select name="time2" id="time2">
                                    <option value="7">7am</option>
                                                           ...SNIP...
                                    <option value="21">9pm</option>
                                  </select>
                                </p>
                               <font color="red"><div id="descriptionError"></div></font>
                                <p>Short Description of your needs<br />
                                  <textarea cols="45" rows="10" name="body" id="body"></textarea>
                                </p>
                                <font color="red"><div id="recaptchaError"></div></font>
                                <p><?php echo recaptcha_get_html($publickey); ?></p>
                                <p>
                                  <label>
                                  <input type="submit" value="Submit">
                                  </label>
                                </p>
                              </form>
                       ...SNIP...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.