Skip to content

Instantly share code, notes, and snippets.

@sruli
Last active December 11, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sruli/4545272 to your computer and use it in GitHub Desktop.
Save sruli/4545272 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() {
if(dropdowns[i].value != "") {
if(document.getElementsByClassName(dropdowns[i].id).length == 0) {
var input = document.createElement("input");
input.type = "hidden";
input.className = dropdowns[i].id;
input.name = "lists[]";
input.value = "108";
form.appendChild(input);
}
} else {
var input = document.getElementsByClassName(dropdowns[i].id);
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