I have the following AJAX script which is for a contact form on my page
$(function() {
// Get the form.
var contactForm = $('#contactForm');
// Get the messages div.
var formMessages = $('#form-messages');
// Set up an event listener for the contact form.
$(form).submit(function(e) {
// Stop the browser from submitting the form.
e.preventDefault();
// Serialize the form data.
var formData = $(form).serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
})
:
:
HTML
<form id="contactForm" name="contactForm" action="php-scripts/contact-form.php" method="post">
<label for="name">Name</label>
<br />
<input type="text" name="name" id="conName" />
<br />
<label for="email">Email</label>
<br />
<input type="text" name="email" id="conEmail" />
<br />
<label for="phone">Phone</label>
My Problem
On my web console I get the error:
ReferenceError: form is not defined
$(form).submit(function(e)
As a newbie to AJAX I cant see why I am getting this error, any help will be appreciated
If you need any more info to help please let me know