justinede Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
Adam Posted March 9, 2010 Share Posted March 9, 2010 You could just use JavaScript's reset() method. Link to comment https://forums.phpfreaks.com/topic/194563-submit-without-refresh-clear-inputs/#findComment-1023449 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.