I am using a piece of code to ignore empty input boxes when processing a form with the GET method. It is working for the text inputs but not for the checkboxes I have in the form. The code I am using is
function SubmitForm(pForm) {
var getString = "";
var elems = pForm.getElementsByTagName('input');
for(var i = 0; i < elems.length; i++) {
if(elems[i].type == "submit") {
continue;
}
if(elems[i].value != "") {
getString += encodeURIComponent(elems[i].name) + "=" + encodeURIComponent(elems[i].value) + "&";
}
}
window.location = pForm.action + getString;
return false;
}
The HTML for my form is
<form action="game_finder.php?" method="GET" onsubmit="return SubmitForm(this);">
<input type="checkbox" name="system[]" value="Warhammer 40k">Warhammer 40k
<input type="checkbox" name="system[]" value="Kill Team">Kill Team
<input type="checkbox" name="system[]" value="Warhammer Quest: Blackstone Fortress">Warhammer Quest:
Blackstone Fortress
<input type="checkbox" name="system[]" value="Necromunda">Necromunda
Any help is appreciated.
Aucun commentaire:
Enregistrer un commentaire