I have a button on click of it, I'am crating a select box dynamically with 4 options, the first option will be "select value" the rest are "aaa","bbb","ccc" now what I need is, when I select aaa as an option in the select box, and now when I click on the button I will get the second select box, but the aaa option shouldn't be there, and when I change the first select option from aaa to bbb the aaa option should appear again in the select box. and the rest is same as the above. Kindly provide a solution for this . Any help would be appreciated.
<button id="addIdButton" style="display:block;" onclick="addId()">clickMe</button>
<div id="place"></div>
<script>
function addId() {
var location = document.getElementById("place");
var div = document.createElement("div");
var span = document.createElement("span");
var select = document.createElement("select");
select.setAttribute("id","selectID" );
select.setAttribute("onchange","hideId(this.value,'selectID','option0','option1')" );
var option0 = document.createElement("option");
option0.setAttribute("id","option0" );
option0.innerHTML="select";
select.appendChild(option0);
var option1 = document.createElement("option");
option1.setAttribute("id","option1" );
option1.innerHTML="aaaa";
select.appendChild(option1);
var option2 = document.createElement("option");
option2.innerHTML="bbbb";
select.appendChild(option2);
var option3 = document.createElement("option");
option3.innerHTML="cccc";
select.appendChild(option3);
span.appendChild(select);
div.appendChild(span);
location.appendChild(div);
}
</script>
I really don't understand how to do it and check for all the conditions. Above is the creation code, please help with the deletion code.
and when I change the first select option from aaa to bbb the aaa option should appear again in the select box" and instead "bbb" should disappear from the second selectbox?