Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Array Data Refers To Drop Down Menu?!?

Status
Not open for further replies.

kanin247

Programmer
Apr 23, 2001
113
US
When using a drop down menu, how do you make the users selected choice refer to specific data in an array and use this data in an equation?

i.e.
Select Type (drop down menu)
- acsr 1351
- al 477
- cu '1/0'

Array [X,Y,Z]
[0.0803,0.369,0.0838] //data for acsr 1351
[0.0829,0.378,0.0855] //data for al 477
[0.1128,0.389,0.0890] //data for cu '1/0'

Equation
XF=Y*100/33

So, when the user selects a type, the values for that type are used in the equation.

Thanks for you help.
~kanin
 
Here is a little working example...
Code:
<html>
<script language=&quot;javascript&quot;>

var aCoordinates = new Array()
aCoordinates[0] = new ParseCoordinates(0.0803,0.369,0.0838) //data for acsr 1351
aCoordinates[1] = new ParseCoordinates(0.0829,0.378,0.0855) //data for al 477
aCoordinates[2] = new ParseCoordinates(0.1128,0.389,0.0890) //data for cu '1/0'

function ParseCoordinates(x,y,z){
 this.x = x;
 this.y = y;
 this.z = z;
}

function GetResult(numSelection){
	var x = aCoordinates[numSelection].x;
	var y = aCoordinates[numSelection].y;
	var z = aCoordinates[numSelection].z;
	
	var XF=y*100/33;
	document.forms.frmCoordinates.txtResult.value = XF;
}
</script>
<body>
<form id=frmCoordinates name=frmCoordinates>
	<select id=selCoordinates>
	 <option value=0>acsr 1351
	 <option value=1>al 477
	 <option value=2>cu '1/0'
	</select>
	  
	<input type=button value=&quot;Get Result&quot; onClick=&quot;GetResult(frmCoordinates.selCoordinates.options[selCoordinates.selectedIndex].value);&quot;>
	<p>
		Result: <input type=text readonly value=&quot;&quot; id=txtResult>
	</p>
</form>
</body>
</html>
For the ultimate in ease of use you could extend the array to add the option text and create the select area on the fly.

Hope it helps, Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top