I am not used to building code with AJAX . So, I need your valuable help . I have the following code . The problem is when a user fills out all the fields of my form and clicks the button reservation , php shows the message 'your reservation has been completed successfully' , but my JS Code doesn't work . It only works when a user clicks the button submit but without completing the fields of my form . Does anyone have any idea of what is happening or anything that I could try ? thank you all of you for your time and effort .
I will post the url of my live web site. http://portfoliozervas.heliohost.org/kalnterimi/en/contactus.php
I will post the url of my live web site. http://portfoliozervas.heliohost.org/kalnterimi/en/contactus.php
Code:
$(document).ready(function(){
$('#reservation').click(function(){
var fname = $('#firstname').val();
var lname = $('#lastname').val();
var total_number_people = $('#total-number-people').val();
var visit_date = $('#visit-date').val();
var visit_hour = $('#visit-hour').val();
var telephone_number = $('#telephone-number').val();
var email = $('#email').val();
if(fname=='' || lname=='' || total_number_people=='' || visit_date=='' || visit_hour=='' || telephone_number==''|| email=='')
{
$('#error_message').html("<h1>You must fill out all the fields of the form</h1>");
}
else
{
$('#error_message').html('');
$.ajax({
url:"contactus.php",
method:"POST",
data:{fname:fname,lname:lname,total_number_people:total_number_people,visit_date:visit_date,visit_hour:visit_hour,telephone_number:telephone_number,email:email},
success:function(data){
$("#myform").trigger("reset");
$('#success_message').fadeIn().html(data);
setTimeOut(function(){
$('#success_message').fadeOut('slow');
},4000);
}
});
}
});
});
Comment