I am submitting a form using ajax and what I need to do is reset the form once a successful submission has been made. However, what is happening is that the form is being cleared once the user submits. I have tried to place the code in Success, Complete but it keeps resetting even if a user receives the error message. I only need to reset after the else statement. ie; The user receives the success message. How can I correct this. Thanks
$.ajax({
type: "POST",
url: "boxrtrvajax.php",
cache: false,
data: send,
success: function (data) {
if (data == 'No data'){
$('#brtv-result').addClass("result_msg").html('Please fill in all fields');
}
else
//location.reload(true);
$('#brtv-result').addClass("result_msg").html("You have successfully retrieved: "+data).fadeIn(4000).delay(4000).fadeOut(4000);
$("#BRV-brtrv-slider").val(0).slider("refresh");
$("input[type='radio']").attr("checked",false).checkboxradio("refresh");
var myselect = $("select#BRV-brtrv-department");
myselect[0].selectedIndex = 0;
myselect.selectmenu("refresh");
var myselect = $("select#BRV-brtrv-address");
myselect[0].selectedIndex = 0;
myselect.selectmenu("refresh");
},
error:function (xhr, ajaxOptions, thrownError){
jAlert('There was an exception thrown somewhere');
alert(xhr.status);
alert(thrownError);
}
});
You dont have brackets around your else statement so it completes the code no matter what