itguyme itguyme - 15 days ago 5
Ajax Question

Ajax show form after submit

i'm currently using the following ajax code to submit my form:

<script>
$('#reg-form').submit(function(e){

e.preventDefault(); // Prevent Default Submission

$.post('ajaxdmsgsub.php', $(this).serialize() )
.done(function(data){
$('#form-content').fadeOut('slow', function(){
$('#form-content').fadeIn('slow').html(data);

});
})
.fail(function(){
alert('Ajax Submit Failed ...');
});
});
</script>


form:

<div id="form-content">
<form method="post" id="reg-form" autocomplete="off" action="ajaxdmsgsform.php">

<label>Message</label>
<textarea class="txtarea" name="message"></textarea>

<div class="cleared"></div>
<input type="submit" value="Submit Message" class="submitit" onclick="hide('myModal')">
</form>

</div>


after submit my form disappears, I want the form to reset so users can keep submitting without a refresh - i'm using this function like an instant messenger. but have no idea how to keep the form from disappearing.

Answer
$('#form-content').fadeOut('slow', function(){
   $('#form-content textarea, #form-content input').each(function(){
       $(this).val("");
  })
  $('#form-content').fadeIn('slow');
});
Comments