$('.contact-form .btn').on('click', function() { var name = $('.name').val(); var email = $('.email').val(); var message = $('.message').val(); if(!name || !email || !message) { alert("All fields must be filled out"); return false; } else { $.ajax({ type: "POST", url: "https://www.example.com/contact-form", data: { name, email, message }, success: function(response) { alert("Message sent successfully!"); }, error: function() { alert("Error sending message. Please try again."); } }); return false; } });