I'm trying to use an ajax contact form to send me emails but i'd like to clear the text fields after the successful sending of the email. I've tried setting the value to val("") but it didnt seem to work. How can I get this to work?
$(document).ready(function(){
$("#ajax-contact-form").submit(function(){
// 'this' refers to the current submitted form
var str = $(this).serialize();
$.ajax({
type: "POST",
url: "inc/contact.php",
data: str,
success: function(msg){
$("#note").ajaxComplete(function(event, request, settings){
if(msg == 'OK') // Message Sent? Show the 'Thank You' message
{
result = '<div class="notification_ok">Your message has been sent. Thank you!</div>';
$("#fields").val("");
}
else
{
result = msg;
}
$(this).html(result);
});
}
});
return false;
});
});
<-------------------------HTML-------------------------->
<center>
<center><h3>A Tableless Contact Form (JQuery & AJAX)</h3></center>
<div align="left" style="width: 500px;">
<fieldset class="info_fieldset"><legend>Contact</legend>
<div id="note"></div>
<div id="fields">
<form id="ajax-contact-form" action="javascript:alert('success!');">
<INPUT class="textbox" type="text" name="name" value=""><br />
<INPUT class="textbox" type="text" name="email" value=""><br />
<INPUT class="textbox" type="text" name="subject" value=""><br />
<TEXTAREA class="textbox" NAME="message" ROWS="5" COLS="25"></TEXTAREA><br />
<INPUT class="button" type="submit" name="submit" value="Send Message">
</form>
</div>
</fieldset>
</div>
</center>