An Example of JavaScript Code

change of pull-down menu  
<SELECT NAME="mode7" onChange="selrate(this, 7)">

function selrate (selOBJ, codeNum) {
    rateArray = new Array("3850 bps","8300 bps","12000 bps","10900 bps","16000 bps","23800 bps","16000 bps","22533 bps","3850\(+12400\) bps","12000\(+11600\) bps");
    beginArray = new Array(0,3,6,8,10);  // the location of first bitrate of each mode in the rate array
    var modeNum = selOBJ.options[selOBJ.selectedIndex].value; // get mode number

    var tempOBJ = eval("document.selFORM.rate"+codeNum+".options"); // the right side pull-down menu
    tempOBJ.options.length = 0;  // set the length of the pull-down menu
    tempOBJ.options[0] = new Option('bitrate','-1'); // set the name of first item of the right side pull-down menu
    tempOBJ.options[0].selected = true; // set the status of first item to be selected

    var bak = 1;
    if( modeNum == '-1' ) { // no mode is selected
      tempOBJ.options[0] = new Option('-','-1'); // if mode is not selected, rewrite the name of first item
    } else {
      for (k = beginArray[modeNum-1]; k < beginArray[modeNum]; k++) {
        tempOBJ.options[bak] = new Option(rateArray[k], bak++);
// add a item to the pull-down menu
      }
    }
}

previous   next