The code is below, not sure what I am missing or what I may need to edit. I am newer to JavaScript. Please help! I have tried to add "onClick" as well as the final submit, the following code (as it's labeled in the bigger code) is "contact submit". I bought this website for my graphic design portfolio - I can read coding to a degree, but this one is throwing me through a loop.
$("#submit_btn").click(function(){
var user_name=$('input[name=name]').val();
var user_email=$('input[name=email]').val();
var user_message=$('textarea[name=message]').val();
var proceed=true;
if(user_name==""){
$('input[name=name]').css('border','2px solid #F54A4B');
proceed=false
}
if(user_email==""){
$('input[name=email]').css('border','2px solid #F54A4B');
proceed=false
}
if(user_message==""){
$('textarea[name=message]').css('border','2px solid #F54A4B');
proceed=false
}
if(proceed){
post_data={'userName':user_name,'userEmail':user_email,'userMessage':user_message};
$.post('php/contact_me.php',
post_data,
function(data){
$("#result").hide().html('<div class="success">'+data+'</div>').fadeIn(700);
$('#contact_form input').val('');
$('#contact_form textarea').val('')}).fail(
function(err){
$("#result").hide().html('<div class="error">'+err.statusText+'</div>').fadeIn(1500)
});
}
});
$("#contact_form input, #contact_form textarea").keyup(function(){
$("#contact_form input, #contact_form textarea").css('border','2px solid #fff');
$("#result").fadeOut(700)
});
To submit a form you have to use .submit()
function.
Use $("#submit_btn").submit()
to submit the form.
Please go through https://api.jquery.com/submit/ once.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.