Lookup Array Item based on Selected Item in List

[Total: 0    Average: 0/5]

This example looks up the selected item in a list and uses the array index to determine the price to show for that item.

Head Code:

<SCRIPT LANGUAGE="Javascript"> 

var selPrice=new Array(4) 
selPrice[0]=10.00 
selPrice[1]=50.00 
selPrice[2]=30.00 
selPrice[3]=15.00 

function getPrice() { 
for (var i=0; i < document.exf1.itemlist.length; i++) { 
if (document.exf1.itemlist[i].selected) { 
document.exf1.price.value = selPrice[i];
}} 
} 
</SCRIPT> 

Body Code:

<form name=exf1> 
Item:  
<select name="itemlist"> 
<option>Book Stands 
<option>Keyboard 
<option>Mouse 
<option>Pad 
</select> 
<input type="button" value="Price" onClick="getPrice()"> 
 <input type="text" name="price" size=7> 
</form> 

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *