Initialize the SELECT on the fly

[Total: 0    Average: 0/5]

The script initialize the FORM’s SELECT control on the fly.

Head Code:

<script type="text/javascript">
<!--
//Author: Peter Daroczy
//function minmax(actype)
//*purpose: initialize the SELECT controls in the <form name='data'> on the fly from the selecttext and selectvalue
//          arrays
//          sets the min max values in the form SELECT controls up
//@actype can be: 'rent' or 'buy' or 'velocity' or what you define in the selecttext and selectvalue array
//(selectvalue and selecttext arrays contain the appropriete text's and code values for the SELECT controls)

function minmax(actype,min,max)
{

//User defined selecttext and selectvalue arrays
  selectvalue = new Array();
  selectvalue.rent = new Array('0','1','2','3','4','5','6','7');
  selectvalue.buy = new Array('0','1','2','3','4','5','6','7','8','9','10','11','12');
  selectvalue.velocity = new Array('0','1','2','3','4','5','6');

  selecttext = new Array();
  selecttext.rent = new Array('0 Eur','300 Eur','600 Eur','900 Eur','1 200 Eur','1 500 Eur','1 800 Eur','2 100 Eur et +');
  selecttext.buy = new Array('0 Eur','40 000 Eur','80 000 Eur','120 000 Eur','160 000 Eur','200 000 Eur','240 000 Eur','280 000 Eur','320 000 Eur','360 000 Eur','400 000 Eur','440 000 Eur','480 000 Eur et +');
  selecttext.velocity = new Array('0 km/h','4 km/h','15 km/h','30 km/h','50 km/h','100 km/h','150 km/h');


 var f = eval('document.data.'+ min);       //data is the formname
 var g = eval('document.data.'+ max);
    f.options.length = 0;
    g.options.length = 0;

    for(var i=0; i<eval("selecttext."+actype+".length-1"); i++)
    {
      f.options[f.options.length]
         = new Option(eval("selecttext."+ actype +"[i]"),eval("selectvalue." + actype +"[i]"));

      g.options[g.options.length]
         = new Option(eval("selecttext."+ actype +"[i+1]"),eval("selectvalue." + actype +"[i+1]"));
    }
    f.options[0].selected = true;
    g.options[eval("selecttext."+actype+".length-2")].selected = true;
}


//function limits(minfield,maxfield)
//*purpose: sets the min max range limits correctly
//@minfield: lower range limit
//@maxfield: upper range limit

function limits(minfield,maxfield)   //checking the correctness of the minimum and maximum values
{
    var mini = eval('document.forms[0].' + minfield);
    var indemin = mini.selectedIndex;
    var maxi = eval('document.forms[0].' + maxfield);
    var indemax = maxi.selectedIndex;
  if (indemin>indemax)
  {
    //alert("indemin = " + indemin +  " > indemax = " +indemax);
    maxi.selectedIndex = indemin;
  }
}
// -->
</script>

Init Code:

minmax("buy","minbuy","maxbuy");minmax("rent","minrent","maxrent");minmax("velocity","minvelocity","maxvelocity");

Body Code:

<br><h1>Range limiter</h1><br>
<p>The SELECT controls are initialized on the fly.</p><br>
<form action="" name="data" method="get">
Mini buy:
<SELECT NAME="minbuy" onChange="limits('minbuy','maxbuy')">
   <OPTION>--------------------</OPTION>
   <OPTION></OPTION>
   <OPTION></OPTION>
 </SELECT>
 Maxi buy:
 <SELECT NAME="maxbuy" onChange="limits('minbuy','maxbuy')">
    <OPTION>--------------------</OPTION>
    <OPTION></OPTION>
    <OPTION></OPTION>
 </SELECT>
 <br><hr><br>
Mini rent:
<SELECT NAME="minrent" onChange="limits('minrent','maxrent')">
   <OPTION>--------------------</OPTION>
   <OPTION></OPTION>
   <OPTION></OPTION>
 </SELECT>
 Maxi rent:
 <SELECT NAME="maxrent" onChange="limits('minrent','maxrent')">
    <OPTION>--------------------</OPTION>
    <OPTION></OPTION>
    <OPTION></OPTION>
 </SELECT>
 <br><hr><br>
Velocity of the wind mini :
<SELECT NAME="minvelocity" onChange="limits('minvelocity','maxvelocity')">
   <OPTION>--------------------</OPTION>
   <OPTION></OPTION>
   <OPTION></OPTION>
 </SELECT>
Velocity of the wind maxi :
 <SELECT NAME="maxvelocity" onChange="limits('minvelocity','maxvelocity')">
    <OPTION>--------------------</OPTION>
    <OPTION></OPTION>
    <OPTION></OPTION>
 </SELECT>
<br>
<input type="submit">
</form>

Times Viewed: 2

Leave a Reply

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