I am trying to extract the value of an input based on its class and then use that value in an associative array
Here is my current javascript code:
var phone_code = document.getElementsByClassName( 'model' ).value;
var phone = [];
phone["6s"] = "23.52";
phone["5s"] = "9.88";
phone["5Se"] = "14.59";
phone["7"] = "28.49";
phone["s7e"] = "27.49";
phone["s7"] = "23.52";
phone["s6e"] = "21.04";
phone["s6"] = "18.56";
phone["a5"] = "12.61";
phone["j5"] = "7.65";
phone["a3"] = "8.64";
phone["j3"] = "5.17";
phone["p9"] = "16.08";
phone["p9lite"] = "8.64";
document.getElementById("phone-cost").innerHTML = phone[phone_code]
The output from the array is as follows:
Your Phone would cost you £<span id="phone-cost"></span> per month
However, the output just shows "undefined," indicating there might be an issue with the javascript or elsewhere in the process.
The variable `phone_code` should be derived based on the enabled dropdown menu, but I suspect that the problem lies in how I am referencing it within the array.
phone[phone_code]
I am unsure if this is the correct way to reference the variable within an array structure, and I have not found a definitive answer on the proper format to use.
Any insights would be greatly appreciated. Thank you!