I created a list of arrays dynamically, which has the following syntax:
<script>
var item1001 = new Array();
item1001[0] = 1001; //id
item1001[1] = "Item name";
item1001[2] = 500; //item price
item1001[3] = "http://whatever"; //item page link
var item1002 = new Array();
item1002[0] = 1002; //id
item1002[1] = "Item name";
item1002[2] = 600; //item price
item1002[3] = "http://whatever"; //item page link
var item1003 = new Array();
item1003[0] = 1003; //id
item1003[1] = "Item name";
item1003[2] = 700; //item price
item1003[3] = "http://whatever"; //item page link
...
</script>
Now I have a form with a SELECT populated with all the items:
<select name="items" id="items">
<option value="1001">Item name</option>
<option value="1002">Item name</option>
<option value="1003">Item name</option>
...
</select>
Just wanted to retrieve the item price when the select changes, to make some calculations with JavaScript:
jQuery( "#items" ).change(function() {
var myItemPrice="item"+Number(jQuery( "#items" ).val()+"[2]");
console.log("Item price: "+myItemPrice);
var total = Number(myItemPrice - (myItemPrice*5)/100);
console.log("Total: "+total);
});
But I don't know how to access the array, i.e. "item1001[2]" dinamically, based upon "select" value...