Someone helped me find JavaScript code to remove hidden form fields from submission and code that ignores a certain field that I don't want removed (whether it's hidden or not):
$("form").submit(function() {
$(this).find(":hidden").remove(); // hide hidden elements before submitting
});
and
:not(input[name=csrfmiddlewaretoken])
However, I can't for the life of me figure out how to put these together. I'm sure it's a basic JavaScript question, but I can't seem to piece these together.
Does anyone know how to remove all hidden form entries not named csrfmiddlewaretoken
? If you do, I'd really appreciate it.
Thanks a lot.
Someone helped me find JavaScript code to remove hidden form fields from submission and code that ignores a certain field that I don't want removed (whether it's hidden or not):
$("form").submit(function() {
$(this).find(":hidden").remove(); // hide hidden elements before submitting
});
and
:not(input[name=csrfmiddlewaretoken])
However, I can't for the life of me figure out how to put these together. I'm sure it's a basic JavaScript question, but I can't seem to piece these together.
Does anyone know how to remove all hidden form entries not named csrfmiddlewaretoken
? If you do, I'd really appreciate it.
Thanks a lot.
Share Improve this question edited May 23, 2017 at 12:31 CommunityBot 11 silver badge asked Oct 24, 2011 at 4:44 useruser 7,3337 gold badges52 silver badges96 bronze badges3 Answers
Reset to default 11$(this).find(":hidden").not('input[name=csrfmiddlewaretoken]').remove();
Or
$(this).find(":hidden").filter(':not(input[name=csrfmiddlewaretoken])').remove();
Or
$(this).find("input[name!=csrfmiddlewaretoken]:hidden").remove();
$(this).find(":hidden").filter("[name!='csrfmiddlewaretoken']").remove();
You can pass the this
as a context argument, which will be potentially faster than making a jQuery object from it. The :not()
expression can follow the :hidden
without spaces, meaning that it adds a second condition to the :hidden
selector.
$(":hidden:not(input[name=csrfmiddlewaretoken])", this).remove();