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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing arrayname based on form value selected

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
0
0
US
From the codes below, I'm trying to pass the arrayname to the function:
if "value1" is selected, then arrvalue1cfgn and arrvalue1cfgv is passed through to the selectChange function:
\"arr\" + this.value + \"cfgn\" = arrvalue1cfgn
\"arr\" + this.value + \"cfgv\" = arrvalue1cfgv

However, this doesn't seem to work, what is the correct way to pass the array name based on the form value selected?

Thanks!


<SCRIPT LANGUAGE="JavaScript">

var arrvalue1cfgv = new Array("prod1v_val1","prod1v_val2","prod1v_val3");
var arrIvalue1cfgn = new Array("prod1n_val1","prod1n_val2","prod1n_val3");

function selectChange(control, controlToPopulate, ItemArray, ValueArray )
{
var myEle ;
var x ;

for ( x = 0 ; x < ItemArray.length ; x++ )
{
myEle = document.createElement("option") ;
myEle.value = ValueArray[x] ;
myEle.text = ItemArray[x] ;
controlToPopulate.add(myEle) ;
}

}
</SCRIPT>

<SELECT id=product name=product onchange="selectChange(this,Form.Application, \"arr\" + this.value + \"cfgn\", \"arr\" + this.value + \"cfgv\");">

<option value="value1" selected>name1</option>
<option value="value2">name2</option>
</select>
 
Here's one way to do it.
I use associative array quite often and I have used it here
below:

Code:
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">

var arr = new Array();
arr["arrvalue1cfgv"] = new Array("prod1v_val1","prod1v_val2","prod1v_val3");
arr["arrIvalue1cfgn"] = new Array("prod1n_val1","prod1n_val2","prod1n_val3");

arr["arrvalue2cfgv"] = new Array("prod2v_val1","prod2v_val2","prod2v_val3");
arr["arrIvalue2cfgn"] = new Array("prod2n_val1","prod2n_val2","prod2n_val3");

function selectChange(control)
{
  var myEle ;
  var x ;
  
  for ( x = 0 ; x < arr["arr"+control.value+"cfgv"].length  ; x++ )
  {
       alert(arr["arr"+control.value+"cfgv"][x]);
       myEle = document.createElement("option") ;
       myEle.value = ValueArray[x] ;
       myEle.text = ItemArray[x] ;
       controlToPopulate.add(myEle);
  }
    
}
</SCRIPT>



</head>
<body>
<SELECT id=product name=product onchange="selectChange(this);">
<option selected></option>
<option value="value1">name1</option>
<option value="value2">name2</option>
</select>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top