Clear a Form
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}
Reset a Form
That said, we often don't want to clear a form – we want to reset it. This is how:
document.forms['myFormName'].reset();
Posting Back Form Values
$("#postform").submit(function() {
var ser = $(this).serialize(); //produced above response
$.post($(this).attr("action"),
ser,
function(response)
{
$("#results").html(response);
});
});