I'm using jQuery to dynamically set the options available in one select box based on the option selected in another select box. But when I select an option I get the error:
Uncaught TypeError: Cannot use 'in' operator to search for '2' in entop_1
The number listed in this example error as '2' and variable "entop_1" change based on which option is selected. Any help with this issue would be appreciated.
I'm currently using jQuery 2.0.0 min. The form used is:
<form id="addForm">
<!-- Ent Select -->
<select id="ent_id" name="ent_id">
<option value="0">- Select -</option>
<option value="1">Ent 1</option>
<option value="2">Ent 2</option>
<option value="3">Ent 3</option>
</select>
<!-- Cat Select -->
<select id="cat_id" name="cat_id"></select>
</form>
And the script is:
<script type="text/javascript">
var entop_1 = {"- Select -": "0","Option A": "1","Option B": "2",};
var entop_2 = {"- Select -": "0","Option C": "3","Option D": "4",};
var entop_3 = {"- Select -": "0","Option E": "5","Option F": "6",};
$("#ent_id").change(function()
{
var $cat_set = $("#cat_id");
$cat_set.empty(); // remove old options
var $ent_var = $("#ent_id option:selected").val();
$.each('entop_' + $ent_var, function(key, value) {
$cat_set.append($("<option></option>").attr("value", value).text(key));
});
});
</script>