In my php file I have two select menus. When the first one is selected second one gets the values with jquery. It works fine in simple php file. But when pasted to a file with JQuery mobile a little problem occurs:
With changing the first one, values of the second one changes fine but the first one’s selected option still remains.
Here is my .js file:
function deg(){
var id = document.getElementById("il").options[document.getElementById("il").selectedIndex].value;
var ilcx;
switch(id){
case "a":
ilcx = {"x" : "x"
}; break;
case "b":
ilcx = {"y" : "y"
}; break;
case "c":
ilcx = {"c" : "c"
}; break;
}
var $el = $("#ilcx");
$el.empty();
$.each(ilcx, function(key, value) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
and php’s part:
<select name="il" id="il" onchange="deg();">
<option id="a" value="a">a</option>
<option id="b" value="b">b</option>
<option id="c" value="c">c</option>
</select>
<select name="ilcx" id="ilcx">
<option id="x" value="x">x</option>
<option id="y" value="y">y</option>
<option id="z" value="z">z</option>
</select>
Made a jsfiddle with the solution
HTML
JS