Forum Moderators: open
$(function() {
function validateForm() {
var x = document.forms["myForm"]["your_email"].value;
var atpos = x.indexOf("@");
var dotpos = x.lastIndexOf(".");
if (atpos < 1 || dotpos < atpos + 2 || dotpos + 2 >= x.length) {
alert("Not a valid e-mail address");
return false;
}
var x = document.forms["myForm"]["your_name"].value;
if (x == null || x == "") {
alert("Your name must be filled out");
return false;
}
return true;
}
$('#form').submit(function(e) {
// Stop the form actually posting
e.preventDefault();
if (validateForm())
// Send the request
$.post('contact.php', {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
address: $('#address').val(),
message: $('#message').val(),
},
function(myform) {
console.log(myform);
// Here we handle the response from the script
// We are just going to alert the result for now
alert(myform);
$('#name').val('');
$('#email').val('');
$('#phone').val('');
$('#address').val('');
$('#message').val('');
}
// Below Function Executes On Form Submit
function myFunction() {
// Storing Field Values In Variables
var name = document.getElementById("name").value;
var email = document.getElementById("email").value;
var phone = document.getElementById("phone").value;
var address = document.getElementById("address").value;
var message = document.getElementById("message").value;
// Regular Expression For Email
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
// Conditions
if (name != '' && email != '' && contact != '') {
if (email.match(emailReg)) {
if (phone.length == 10) {
alert("All type of validation is done.");
document.getElementById("myForm").submit();
return true;
} else {
alert("The Contact No. must be at least 10 digit long!");
return false;
}
} else {
alert("Invalid Email Address...!");
return false;
}
} else {
alert("All fields are required.....!");
return false;
}
}
);
});
});