Skip to content

Instantly share code, notes, and snippets.

@abor123
Created September 13, 2016 15:48
// Javascript for Thank You display after form submission in contact me region
$(function ()
{
$('form').submit(function (e)
{
e.preventDefault();
// $('#please_wait').show();
if(e.target === document.getElementById("info-form"))
{
$('#please_wait_info').show();
}
else
{
$('#please_wait_contact').show();
}
$.ajax(
{
url: this.action,
type: this.method,
data: $(this).serialize(),
success: function (response)
{
console.log(response);
if(response.result == 'success')
{
// Determine if the submission came from "Info Form" or "Contact Form"
if(e.target === document.getElementById("info-form"))
{
document.getElementById("thankyou_info").style.display = "inline";
document.getElementById("form_link").style.display = "inline";
$('#please_wait_info').hide();
document.getElementById("info-form").reset();
}
else
{
document.getElementById("thankyou_contact").style.display = "inline";
$('#please_wait_contact').hide();
document.getElementById("contact-form").reset();
}
}
else
{
if(e.target === document.getElementById("info-form"))
{
document.getElementById("thankyou_info").style.display = "none";
document.getElementById("sorry_info").style.display = "inline";
}
else
{
document.getElementById("thankyou_contact").style.display = "none";
document.getElementById("sorry_contact").style.display = "inline";
}
}
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment