I am trying to redirect to a contact form on submit to a HTML file which I have made using.
JavaScript
x
2
1
header('Location: /dev/thanks.html');
2
However, this loads it to a different page and not to the page that I’m already on.
I already have the jQuery to make a popup for the contact form and information page, which is:
JavaScript
1
16
16
1
$('a.contact , a.contact_footer, a.contact_text').click(function() {
2
$("html, body").animate({ scrollTop: 0 }, 600);
3
$("#popup").load("/dev/contact.php");
4
// Getting the variable's value from a link
5
var show = $('#popup').css('display', 'block'),
6
popup = $(this).attr('href');
7
8
//Fade in the Popup and add close button
9
$(popup).fadeIn(300);
10
11
// Add the mask to body
12
$('body').append('<div id="mask"></div>');
13
$('#mask').fadeIn(300);
14
15
return false;
16
On submitting the contact form, I want to load a new file (thanks.html) to replace the popup (contact form) with a thank-you message. Similar to what I’m doing with the jQuery already, but I want it to only implement on submit:
JavaScript
1
4
1
<div class="submit">
2
<input type="submit" value="Submit"/>
3
</div>
4
What do I need to do to modify my jQuery so it implements on submit instead of on click?
Advertisement
Answer
Add the submit event to the contact form:
If you use jQuery 1.7+, use on:
JavaScript
1
5
1
$(document).on("submit", "form#submit_message", function() {
2
$('#popup').load('/dev/thanks.html');
3
return false;
4
});
5
If not, use live (or upgrade your jQuery version):
JavaScript
1
6
1
//live is old deprecated
2
$('form#submit_message').live('submit', function() {
3
$('#popup').load('/dev/thanks.html');
4
return false;
5
});
6