Jump to content

Submit without refresh + clear inputs


justinede

Recommended Posts

Currently, I have a page that has a form. You can submit the form without reloading the page using this ajax set-up.

The only problem I am having is that I want it to clear the form once it has been submitted. I have tried what I thought would work and it dosnt work.

 

I have the function hide being called when the form is successful.

 

<script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" >

$(function() {

function hide () {

$("name").value = "";

$("email").value = "";

}

$(".submit").click(function() { 

var name = $("#name").val();

var email = $("#email").val();

var dataString = 'name='+ name + '&email=' + email;



if(name=='' || email=='')

{

$('.success').fadeOut(200).hide();

$('.error').fadeOut(200).show();

}

else

{

$.ajax({

type: "POST",

url: "join.php",

data: dataString,

success: function(){

hide();

$('.success').fadeIn(400).show();

$('.error').fadeOut(400).hide();

}

});

}

return false;

});

});
</script>

 

Thanks for the help.

Link to comment
https://forums.phpfreaks.com/topic/194563-submit-without-refresh-clear-inputs/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.