Reputation: 3
First of all: I tried to search the answer in the web and I found like 20 examples of code. But I failed. still nothing is working.
I'm making a simple chat and i need to clean my form after submitting data via ajax. Here is the code:
<form id="ChatFrom" class="chatMessageField" action="Amess.php" method="post">
<input class="chatMessageField" type="text" name="mess" /><br />
<input class="chatMessageBtn" type="button" value="Отправить" onclick="SendForm();" />
</form>
<script type="text/javascript" src="http://scriptjava.net/source/scriptjava/scriptjava.js"></script>
<script type="text/javascript">
function SendForm() {
$$f({
formid:'ChatFrom',
url:'Amess.php',
});
}
</script>
Upvotes: 0
Views: 1396
Reputation: 492
You could do it like this:
function SendForm() {
$.post( "Amess.php", function( data ) {
resetFields();
});
}
function resetFields(){
$(':input')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
}
Hope it helps!
Upvotes: 1
Reputation: 1977
$(".chatMessageField").val(''); is a simple way, but you have to do it to all the fields individually. A better solution would be to give all of your inputs a class name that is the same and clear them all at once. Or just use jquery reset()
Upvotes: 0