Bulding Select Lists from Constructs

[Total: 0    Average: 0/5]

Building dynamic select lists.

Head Code:

<script>
/*
 * Construct to hold the data pair
 */
function pairClass(_label,_value)
{
  this.LABEL=_label;
  this.VALUE=_value;
  this.labelIs=function(){return this.LABEL;}
  this.valueIs=function(){return this.VALUE;}
}

var _i=0;
var Pairs1=new Array();
Pairs1[_i++]=new pairClass("1-Competing"     ,11);
Pairs1[_i++]=new pairClass("1-One on One"    ,12);
Pairs1[_i++]=new pairClass("1-Move w/o Ball" ,13);
Pairs1[_i++]=new pairClass("1-Rebounding"    ,14);
Pairs1[_i++]=new pairClass("1-Offensive "    ,15);
Pairs1[_i++]=new pairClass("1-Defense"       ,16);

_i=0; /* reset for next pair */
var Pairs2=new Array();
Pairs2[_i++]=new pairClass("2-Competing"     ,21);
Pairs2[_i++]=new pairClass("2-One on One"    ,22);
Pairs2[_i++]=new pairClass("2-Move w/o Ball" ,23);
Pairs2[_i++]=new pairClass("2-Rebounding"    ,24);
Pairs2[_i++]=new pairClass("2-Offensive "    ,25);
Pairs2[_i++]=new pairClass("2-Defense"       ,26);


function ex_init()
{
  var _f=document.f1;
  var _s1=_f.s1;
  var _s2=_f.s2;
  for(var i=0;i<Pairs1.length;i++)
  {
    _s1.options[i]=new Option(Pairs1[i].labelIs(),Pairs1[i].valueIs());
  }
  for(var i=0;i<Pairs2.length;i++)
  {
    _s2.options[i]=new Option(Pairs2[i].labelIs(),Pairs2[i].valueIs());
  }
}
</script>

Init Code:

ex_init();

Body Code:

<form name=f1>
<select name=s1></select>
<select name=s2></select>
<input type=submit>
</form>

Times Viewed: 4

Leave a Reply

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