Ver Mensaje Individual
  #6 (permalink)  
Antiguo 10/01/2006, 02:43
mekir
 
Fecha de Ingreso: noviembre-2005
Mensajes: 55
Antigüedad: 19 años
Puntos: 0
Tres.

************************************************** ****
************************************************** ****

6) selectphp.js:

// constants
var noValue = '-99';
// default values
var IDMake = noValue;
var IDModel = noValue;
var IDOptions = noValue;
var IDOptions2 = noValue;

//selects disabled true/false
var boolEnabled = true;

// globals
var curOption = new Array();
var isLoaded = new Array();

function initLists(){
// initialize lists
emptyList( 'lstMake' );
emptyList( 'lstModel');
emptyList( 'lstOptions' );
emptyList( 'lstOptions2' );

jsrsExecute( 'select_rs.php', cbFillMake, 'makeList');
}

function preselect(idMake,idModel,idOptions,idOptions2,sele ctable){
boolEnabled = selectable;
IDMake = idMake;
IDModel = idModel;
IDOptions = idOptions;
IDOptions2 = idOptions2;
initLists();
}

function lstMake_onChange(){
var val = this.options[this.selectedIndex].value;
IDMake = val;
IDModel = noValue;
IDOptions = noValue;
IDOptions2 = noValue;

if(val == noValue){
selectOption( this.name, curOption[this.name] )
} else {
curOption[this.name] = val;
// init dependent lists
emptyList( 'lstModel' );
emptyList( 'lstOptions');
emptyList( 'lstOptions2');
window.status = 'Loading Model Selections...';
jsrsExecute( 'select_rs.php', cbFillModel, 'modelList', val);
}
}

function lstModel_onChange(){

var val = this.options[this.selectedIndex].value;
if(val == noValue){
selectOption( this.name, curOption[this.name] )
} else {
curOption[this.name] = val;
emptyList( 'lstOptions');
emptyList( 'lstOptions2');
window.status = 'Loading Options Selections...';
jsrsExecute( 'select_rs.php', cbFillOptions, 'optionsList', val);
}
}

function lstOptions_onChange(){

var val = this.options[this.selectedIndex].value;
if(val == noValue){
selectOption( this.name, curOption[this.name] )
} else {
curOption[this.name] = val;
emptyList( 'lstOptions2');
window.status = 'Loading Options Selections...';
jsrsExecute( 'select_rs.php', cbFillOptions2, 'optionsList2', val);
}
}



function lstOptions2_onChange(){
var val = this.options[this.selectedIndex].value;
IDOptions2 = val;
if(val == noValue){
selectOption( this.name, curOption[this.name] )
} else {
var msg = "You have selected: \n\n";
msg += this.form.lstMake.options[this.form.lstMake.selectedIndex].text + "\n";
msg += this.form.lstModel.options[this.form.lstModel.selectedIndex].text + "\n";
msg += this.form.lstOptions.options[this.form.lstOptions.selectedIndex].text + "\n";
msg += this.options[this.selectedIndex].text + "\n";
//alert (msg);

if(boolEnabled){
document.getElementById('cmdSubmit').disabled="";
document.getElementById('show').style.backgroundCo lor="#FFCC99";
}

}
}

function cbFillMake ( strMakes ){
window.status = '';
fillList( 'lstMake', strMakes );
if(IDMake != noValue){
jsrsExecute( 'select_rs.php', cbFillModel, 'modelList', ''+IDMake+'');
}
}

function cbFillModel ( strModels ){
// callback for dependent listbox
window.status = '';
fillList( 'lstModel', strModels );
if(IDModel != noValue){
jsrsExecute( 'select_rs.php', cbFillOptions, 'optionsList', ''+IDModel+'');
}
}

function cbFillOptions( strOptions ){
// callback for dependent listbox
window.status = '';
fillList( 'lstOptions', strOptions );
if(IDOptions != noValue){
jsrsExecute( 'select_rs.php', cbFillOptions2, 'optionsList2', ''+IDModel+'');
}
}


function cbFillOptions2( strOptions2 ){
// callback for dependent listbox
window.status = '';
fillList( 'lstOptions2', strOptions2 );
}

function fillList( listName, strOptions2 ){
// fill any list with options
emptyList( listName );

// always insert selection prompt
var lst = document.forms['QForm'][listName];
lst.disabled = true;
lst.options[0] = new Option('=> Please Select <=', noValue);

// options in form "value~displaytext|value~displaytext|..."
var aOptionPairs = strOptions2.split('|');
for( var i = 0; i < aOptionPairs.length; i++ ){
if (aOptionPairs[i].indexOf('~') != -1) {
var aOptions = aOptionPairs[i].split('~');
lst.options[i + 1] = new Option(aOptions[1], aOptions[0]);
}
}
switch(listName){
case 'lstMake':
ID = IDMake;
break;
case 'lstModel':
ID = IDModel;
break;
case 'lstOptions':
ID = IDOptions;
break;
case 'lstOptions2':
ID = IDOptions2;
break;
}
// init to no value
selectOption( listName, ID );
isLoaded[listName] = true;
lst.disabled = !boolEnabled;
lst.onchange = eval( listName + "_onChange" );
// eval( "document.forms['QForm']['" + listName + "'].onchange=" + listName + "_onChange;" );
}

function emptyList( listName ){
var lst = document.forms['QForm'][listName];
lst.options.length = 0;
lst.onchange = null;
lst.disabled = !boolEnabled;
isLoaded[listName] = false;
curOption[listName] = noValue;
}

function selectOption( listName, optionVal ){
// set list selection to option based on value
var lst = document.forms['QForm'][listName];
for( var i = 0; i< lst.options.length; i++ ){
if( lst.options[i].value == optionVal ){
lst.selectedIndex = i;
curOption[listName] = optionVal;
return;
}
}
}


************************************************** ****
************************************************** ****