Sorry, I am very new to AJAX, and I while there are tons of examples out there, it is hard for me to understand. If you could please help me out with my specific example I'd much appreciate it. The AJAX syntax is just very strange to me. Anyway, I am validating a contact form in javascript. If it every field has values in it, then it is to call a php function included in the page to send the email. Could someone please show me how to do this and EXPLAIN it? I am very confused by how AJAX works. Server/client differences? Sorry. Thank you. Here is my code (that fails not using AJAX):
<?php
require_once("mail.php");
?>
<script language='Javascript' type='text/javascript'>
function validation(){
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var phone = document.getElementById('phone').value;
var subject = document.getElementById('subject').value;
var message = document.getElementById('message').value;
if (name == '') {
alert('Please enter your name.');
location.reload(false);
}
else {
if (email == '') {
alert('Please enter your email.');
location.reload(false);
}
else {
if (phone == '') {
alert('Please enter your phone number.');
location.reload(false);
}
else {
if (subject == '') {
alert('Please enter a subject.');
location.reload(false);
}
else {
if (message == '') {
alert('Please enter a message.');
location.reload(false);
}
else {
var send = confirm('Name: ' + name + '\r\nEmail: ' + email + '\r\nPhone: ' + phone + 'Subject: ' + subject + '\r\nMessage:\r\n' + message + '\r\nPress [Ok] to send or [Cancel] to return to the contact page.');
if (send) {
window.location='';
}
else {
location.reload(false);
}
}
}
}
}
}
}
</script>
I know the javascript works up to the part where I need to invoke the php sendmail() function. Thanks for the help and support!