Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/06/2017, 09:15
Avatar de julia2021
julia2021
 
Fecha de Ingreso: diciembre-2014
Ubicación: Mexico
Mensajes: 152
Antigüedad: 9 años, 4 meses
Puntos: 11
Sonrisa Respuesta: Ampliar listas con JS

Yupiiiii !, les cuento que ya lo pude solucionar, aquí les dejo la respuesta por si acaso a alguien le pueda servir.

En HTML coloque más opciones en el OnChange:
Código HTML:
<select autofocus id="id_cliente" name="id_cliente" onChange="selectChange(this, form.id_contrato, arrContratos, arrContratosId, form.id_sucursal, arrSucursales, arrSucursalesId);" class="select2_group form-control" required="required">
 <option value="">Seleccione un cliente.......
En JS me puse a armar otro select con los nuevos parametros recibidos del HTML
Código Javascript:
Ver original
  1. <? // INICIO: LISTAS DEPENDIENTES: CLIENTE >> CONTRATO ///////////////////// ?>
  2. <? // INICIO: LISTAS DEPENDIENTES: CLIENTE >> SUCURSAL ///////////////////// ?>
  3. <SCRIPT LANGUAGE="JavaScript">
  4. var arrContratos    = new Array();
  5. var arrContratosId  = new Array();
  6. var arrSucursales   = new Array();
  7. var arrSucursalesId = new Array();
  8.  
  9. <? // Armamos la lista desplegable de los CONTRATOS
  10. foreach ($_agreements as $clave => $contrato) {
  11.     echo 'arrContratos['.$contrato['id_contrato'].'] = "'.$contrato['nombre'].' ('.$contrato['codigo'].')'.'"';echo "\n";
  12.     echo 'arrContratosId['.$contrato['id_contrato'].'] = '.$contrato['id_cliente'];echo "\n";
  13. }
  14. ?>
  15. <? // Armamos la lista desplegable de los SUCURSALES
  16. foreach ($_offices as $clave => $sucursal) {
  17.     echo 'arrSucursales['.$sucursal['id_sucursal'].'] = "'.$sucursal['nombre'].' ('.$sucursal['id_sucursal'].')'.'"';echo "\n";
  18.     echo 'arrSucursalesId['.$sucursal['id_sucursal'].'] = '.$sucursal['id_cliente'];echo "\n";
  19. }
  20. ?>
  21. function selectChange(control, controlToPopulate, ItemArray, GroupArray, controlToPopulate2, ItemArray2, GroupArray2)
  22. {
  23.     // Armamos la lista de CONTRATOS
  24.     var myEle ;
  25.     var x ;
  26.     // Empty the second drop down box of any choices
  27.     for (var q=controlToPopulate.options.length;q>=0;q--) controlToPopulate.options[q]=null;
  28.     // ADD Default Choice - in case there are no values
  29.     myEle = document.createElement("option") ;
  30.     myEle.value = 0 ;
  31.  
  32.     if (control.name == "id_cliente") {
  33.         myEle.text = "Seleccione el contrato..." ;
  34.     }
  35.     controlToPopulate.add(myEle) ;
  36.     // Now loop through the array of individual items
  37.     // Any containing the same child id are added to
  38.     // the second dropdown box
  39.     for ( x = 0 ; x < ItemArray.length  ; x++ )
  40.     {
  41.         if ( GroupArray[x] == control.value )
  42.         {
  43.             myEle = document.createElement("option") ;
  44.             myEle.value = x ;
  45.             myEle.text = ItemArray[x] ;
  46.             controlToPopulate.add(myEle) ;
  47.         }
  48.     }
  49.  
  50.     // Armamos la lista de SUCURSALES
  51.     var myEle2 ;
  52.     var x2 ;
  53.     // Empty the second drop down box of any choices
  54.     for (var q2=controlToPopulate2.options.length;q2>=0;q2--) controlToPopulate2.options[q2]=null;
  55.     // ADD Default Choice - in case there are no values
  56.     myEle2 = document.createElement("option") ;
  57.     myEle2.value = 0 ;
  58.  
  59.     if (control.name == "id_cliente") {
  60.         myEle2.text = "Seleccione la oficina..." ;
  61.     }
  62.     controlToPopulate2.add(myEle2) ;
  63.     // Now loop through the array of individual items
  64.     // Any containing the same child id are added to
  65.     // the second dropdown box
  66.     for ( x2 = 0 ; x2 < ItemArray2.length  ; x2++ )
  67.     {
  68.         if ( GroupArray2[x2] == control.value )
  69.         {
  70.             myEle2 = document.createElement("option") ;
  71.             myEle2.value = x2 ;
  72.             myEle2.text = ItemArray2[x2] ;
  73.             controlToPopulate2.add(myEle2) ;
  74.         }
  75.     }
  76. }
  77. //  End -->
  78. </script>
  79. <? // FINAL: LISTAS DEPENDIENTES: CLIENTE >> CONTRATO ///////////////////// ?>
  80. <? // FINAL: LISTAS DEPENDIENTES: CLIENTE >> SUCURSAL ///////////////////// ?>
Espero les sirva a alguien. Besos a todos, Bye.