Ok, javascript beginner here trying to solve a perplexing problem. What I’m trying to accomplish is a drop down select box that has SKU numbers as the option values. The option that is selected should pass the SKU number to a javascript function that searches an array for that SKU and outputs the information contained in that array record to a div on the same page. I cannot create hidden divs for each array record and show/hide them because there will be a large volume of SKU records and to generate hundreds of hidden divs on a page would render it un-useable.
Here is an example of the array and nested objects
[CODE]<script type=”text/javascript” language=”javascript”>
var ScriptSKUs = new Array();
ScriptSKUs[0] = new Object();
ScriptSKUs[0][“sku”] = “BLK-30-7”;
ScriptSKUs[0][“title”] = “Cool Knife 1”;
ScriptSKUs[0][“msrp”] = 249.99;
ScriptSKUs[1] = new Object();
ScriptSKUs[1][“sku”] = “BLK-30-8”;
ScriptSKUs[1][“title”] = “Cool Knife 2”;
ScriptSKUs[1][“msrp”] = 249.99;
;
</script>
This is the form with a select box that displays the possible selections. The onChange event would trigger when a different option was chosen.
[CODE]<form name=”GetItem” method=”post” action=”#”>
Item: <select name=”Items” id=”ItemSelect” class=”select” OnChange=”ShowValue();”>
<option value=”” selected=”selected”>Choose an item</option>
<option value=”BLK-30-7″>Cool Knife 1</option>
<option value=”BLK-30-8″>Cool Knife 2</option>
</select>
</form>
This is the div I want to populate with the information from the array. The information would change when different items are selected from the select box. The “x” signifies the number of the array index.
[CODE]
<div id=”itembuybox”>
ScriptSKUs[x][“sku”]
ScriptSKUs[x][“title”]
ScriptSKUs[x][“msrp”]
</div>
As you can see, I’m missing the function to accomplish this. I’m sure its not incredibly difficult but I can’t figure out the right syntax to loop through the array values for the onChange event. I’m more of a ColdFusion guy… Any help or pointers in the right direction would be extremely helpful. Thanks in advance!
-A!