Skip to content

Instantly share code, notes, and snippets.

@marcheiligers
Forked from sruli/gist:4545272
Last active December 11, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcheiligers/4545351 to your computer and use it in GitHub Desktop.
Save marcheiligers/4545351 to your computer and use it in GitHub Desktop.
addLoadEvent(function() {
var dropdowns = form.getElementsByTagName("select");
for(var i = 0; i < dropdowns.length; ++i) {
dropdowns[i].onchange = (function() {
var dropdown = dropdowns[i];
return function() {
if(dropdown.value != "") {
if(document.getElementsByClassName(dropdown.id).length == 0) {
var input = document.createElement("input");
input.type = "hidden";
input.className = dropdown.id;
input.name = "lists[]";
input.value = "108";
form.appendChild(input);
}
} else {
var input = document.getElementsByClassName(dropdown.id);
// TODO: There be another problem here --------^
if(input.length != 0) {
input[0].parentNode.removeChild(input[0]);
}
}
}
})();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment