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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.