<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<script>
p1=new Array("AF,200","FF,150","RZ,12");
p2=new Array("CD,123","RR,112","TE,23","JU,12","LO,129");
p3=new Array("HG,2","FG,10","LL,422","IO,89");
productTbl=new Array(p1,p2,p3);
function chgPrice(objSelect) {
var selectName=objSelect.name; //Name of the current Select being processed.
var selectNum=selectName.substr("SelectProduct".length); //trailing number of the current select SELECT1 will give us '1';
var theForm=objSelect.form; //the form where the select object is contained
var currentIdx=objSelect.selectedIndex; //the index of the current Option selected
var currentValue=objSelect.options[currentIdx].value; //the value of the the current Option.
if (currentIdx != 0) { //if you select something other thatn the initial option then.....
var prodNumValue=productTbl[selectNum-1][currentIdx-1].split(","); //grab the value pair and break in two parts
document.getElementById("txtProd"+selectNum).value=prodNumValue[0]; // first part is the product number
document.getElementById("txtPrice"+selectNum).value=prodNumValue[1];//second part is the product price
}else{
document.getElementById("txtPrice"+selectNum).value="";//if you select the initial option again, then clear the boxes.
document.getElementById("txtProd"+selectNum).value="";
}
}
</script>
<body><form name="form1" id="form1" method="post" action="">
<table border="2">
<tr>
<th>
</th>
<th>Product Code</th>
<th>Price</th>
</tr>
<tr>
<td>Select # 1:
<select name="SelectProduct1" id="SelectProduct1" onChange="chgPrice(this)">
<option value="">-- Make a Selection --</option>
<option value="AF">Product 1</option>
<option value="FF">Product 2</option>
<option value="RZ">Product 3</option>
</select> </td>
<td><input type="text" value="" name="txtProd1" id="txtProd1"></td>
<td><input type="text" value="" name="txtPrice1" id="txtPrice1"></td>
</tr>
<tr>
<td>Select # 2:
<select name="SelectProduct2" id="SelectProduct2" onChange="chgPrice(this)">
<option value="">-- Make a Selection --</option>
<option value="CD">Product 1</option>
<option value="RR">Product 2</option>
<option value="TE">Product 3</option>
<option value="JU">Product 4</option>
<option value="LO">Product 5</option>
</select>
</td>
<td><input type="text" value="" name="txtProd2" id="txtProd2"></td>
<td><input type="text" value="" name="txtPrice2" id="txtPrice2"></td>
</tr>
<tr>
<td>Select # 3:
<select name="SelectProduct3" id="SelectProduct3" onChange="chgPrice(this)">
<option value="">-- Make a Selection --</option>
<option value="HG">Product 1</option>
<option value="FG">Product 2</option>
<option value="LL">Product 3</option>
<option value="IO">Product 4</option>
</select>
</td>
<td><input type="text" value="" name="txtProd3" id="txtProd3"></td>
<td><input type="text" value="" name="txtPrice3" id="txtPrice3"></td>
</tr>
</table> </form>
</body>
</html>