I have a form generated with the answer of an Ajax request to a PHP page communicating with my database.
When I click on the submit
button, I gather through jQuery for the content of the different form inputs (text,checkbox,textarea,...) in simple arrays to send them back to the database.
Now I want to reset the form
after the submission.
I failed to use myForm.reset()
to clear everything (it did nothing) even with all the methods I found on StackOverflow and the internet in general. So I decided to code the clear process myself.
To the main problem : I gather the values of the checked checkboxes with :
var complement0=[];
complement0.push($("input[name=foo]:checked").map(function() {
return this.value;
}).get());
And then try to uncheck the checkboxes. Here are the ways I tried to do it without success :
$("input[name=foo]:checked").each(function() {
$(this).removeAttr('checked');
});
$("input[name=foo]:checked").map(function() {
return this;
}).removeAttr('checked');
$("input[name=prsFmtLng]:checked").attr('checked',false);
$("input[name=prsFmtLng]:checked").removeAttr('checked');
Since it looks like to be simple when other people talk about this: either I don't understand what I am doing or I am just missing something.
Any help is welcomed.
The answer :
$("input[name=foo]:checked").map(function() {
$(this).prop('checked',false);
});