This is my first time using JSON so I'm not even sure if I'm asking this question correctly but hopefully you can understand what I'm getting at.
I am using the following data that to populate a select option based on the selection made in the previous select:
prods = {
Cookware: ["- Select -", "Round French Oven", "Oval French Oven", "Braiser", "Skillet", "Fry Pan", "Grill Pan", "Saute Pan", "Saucepan", "Saucier", "Griddle", "Roaster", "Stockpot", "Speciality Cookware", "Other"],
Bakeware: ["- Select -", "Covered Casserole", "Baking Dish", "Stoneware Gratin", "Speciality Bakeware", "Individual Bakeware", "Metal Bakeware", "Other"],
KitchenTools: ["- Select -", "Utensils", "Kitchen Accessories", "Cutlery", "Wine Tools", "Textiles", "Other"],
DineEntertain: ["- Select -", "Dinnerware", "Serveware", "Tabletop Accessories", "Glassware", "Kettles", "Tea Collection", "Café Collection", "Other"]
};
and here is the relevant jQuery I am using to do this:
$.each(prods[catSelected], function (key, value) {
nextProdType
.append($("<option></option>")
.attr("value", key)
.attr("name", value)
.text(value));
});
In the resulting HTML, the key counter starts over for each array. So if Bakeware is selected:
<option value="0" name="- Select -">- Select -</option>
<option value="1" name="Covered Casserole">Covered Casserole</option>
<option value="2" name="Baking Dish">Baking Dish</option>
<option value="3" name="Stoneware Gratin">Stoneware Gratin</option>
or if Accessories is selected:
<option value="0" name="- Select -">- Select -</option>
<option value="1" name="Utensils">Utensils</option>
<option value="2" name="Kitchen Accessories">Kitchen Accessories</option>
<option value="3" name="Cutlery">Cutlery</option>
As you can see the value always starts at 0, and what I would like is for the first - select - value to be 0 and the last option in DineEntertain be 39. This would allow me to store all these options in one table in the database without having duplicate numerical values.
I am using this on a dynamic form where users can add or subtract categories, so the value has to be fixed. Is there a way to do this? I have tried searching for this in the forums here and in Google but not finding any solutions, which makes me think I may not be asking the right question...
<option>elements have a name attribute? :)