You can best include multiple sub-values within the value of an option, using a delimiter such as ~ and then splitting the value into an array.
Code:
<select id="selectfruit" onchange = "getValues()">
<option value = "0">Select ......</option>
<option value = "Banana~1~1">Banana</option>
<option value = "Apple~1.2~0.5">Apple</option>
<option value = "Mango~1.1~0.9">Mango</option>
<option value = "Orange~0.1~9.99">Orange</option>
</select>
<script type = "text/javascript">
function getValues() {
var val = document.getElementById("selectfruit").value;
if (val !=0) {
var valSplit = val.split("~");
alert (valSplit[0] + " " + valSplit[1] + " " + valSplit[2])
}
}
</script>
You should not gve the same name or id (
selectfruit, cash, coupons) to an HTML form element and a Javascript function or variable.
If (or as) this is homework and you are required to use an array, then you have the syntax wrong.
Code:
var selectfruit = [];
selectfruit[0] = ["Nothing Selected", 0, 0]; // you must have a default value if you are using onchange
selectfruit[1] = ["Banana", 1, 1];
selectfruit[2] = ["Apple", 1.2, 0.5];
selectfruit[3] = ["Mango", 1.1, 0.9];
selectfruit[4] = ["Orange", 0.1, 9.99];
alert (selectfruit[3][0] + " " + selectfruit[3][2]); // example
Then access the values using selectedIndex.
A politician is one who preaches doctrines he knows to be untrue to men he knows to be idiots."
H. L. Mencken - US editor (1880 - 1956)