Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/11/2016, 15:14
vmoran2009
 
Fecha de Ingreso: febrero-2011
Mensajes: 43
Antigüedad: 13 años, 2 meses
Puntos: 0
combo dependiente php mysql javascript

hola amigos el siguiente codigo crea combos dependientes utilizando php mysql y javacript, a partir del primer select llamado cmbnivel y luego a través de la funcion javascript oficinas actualiza al cmboficina y funciona bien, pero quisiera saber como puedo hacer para que al ver el codigo fuente de la pagina NO APAREZCAN todos los valores que barre la función

Código PHP:
Ver original
  1. if(nivel==='0'){
  2.                 document.f1.cmboficina.disabled = true;
  3.                 document.f1.cmboficina.length=0;
  4.                 document.f1.cmboficina.options[0] = new Option("Seleccione...","","defaultSelected","");
  5.             }
  6.  
  7.             if(nivel==='1'){
  8.                 document.f1.cmboficina.options[i] = new Option("Almacén ","14");
  9.                 i++;
  10.             }
  11.            
  12.             if(nivel==='0'){
  13.                 document.f1.cmboficina.disabled = true;
  14.                 document.f1.cmboficina.length=0;
  15.                 document.f1.cmboficina.options[0] = new Option("Seleccione...","","defaultSelected","");
  16.             }
  17.  
  18.             if(nivel==='1'){
  19.                 document.f1.cmboficina.options[i] = new Option("Ventas","132");
  20.                 i++;
  21.             }

...y así sucesivamente.

es decir quisiera que en el select oficina se generara así y no que me muestre todos los posibles valores que tomo en la funcion javascript:


Código PHP:
Ver original
  1. <select name="cmboficina" id="cmboficina" disabled>
  2.                             <option value="0" >Seleccione...</option>
  3.                             <option value="14" >Almacen</option>
  4.                             <option value="132" >Ventas</option>
  5.                         </select>
  6.  
  7.  
  8.  
  9.  
  10.  
  11. <script type="text/javascript">
  12. function oficinas(nivel)
  13. {
  14.    
  15.     document.f1.cmboficina.disabled = false;
  16.     document.f1.cmboficina.length=0;
  17.     document.f1.cmboficina.options[0] = new Option("Seleccione...","","defaultSelected","");
  18.  
  19.     var i=1;
  20.     <?php
  21.         $sql = "select iddepen,nombre,idnivel from oficinas";
  22.         $rs = mysql_query($sql);
  23.         if (mysql_num_rows($rs) > 0) {
  24.             while ($row = mysql_fetch_array($rs)) {
  25.             ?>
  26.  
  27.             if(nivel==='0'){
  28.                 document.f1.cmboficina.disabled = true;
  29.                 document.f1.cmboficina.length=0;
  30.                 document.f1.cmboficina.options[0] = new Option("Seleccione...","","defaultSelected","");
  31.             }
  32.  
  33.             if(nivel==='<?=$row["idnivel"];?>'){
  34.                 document.f1.cmboficina.options[i] = new Option("<?=$row['dependencia'];?>","<?=$row['iddepen'];?>");
  35.                 i++;
  36.             }
  37.             <?php
  38.             }
  39.         }
  40.     ?>
  41. }
  42.  
  43.  
  44. </script>
  45.  
  46.  
  47.  
  48.  
  49.  <select name="cmbnivel" id="cmbnivel" tabindex="5" onchange="oficinas(this.value)">
  50.                             <option value="0">Seleccione...</option>
  51.                             <?php
  52.                             $sql1="select idnivel,nivel from niveles order by idnivel";
  53.                             $result1= mysql_query($sql1);
  54.                             while ($row = mysql_fetch_array($result1)) {
  55.                                    if ($row[0] == $cmbrol) {
  56.                                     echo "<option value='$row[0]' selected>$row[1]</option>";
  57.                                 } else {
  58.  
  59.                                     echo "<option value='$row[0]'>$row[1]</option>";
  60.                                 }
  61.                             }
  62.                             ?>
  63.                         </select>
  64.  
  65. <select name="cmboficina" id="cmboficina" disabled>
  66.                             <option value="0" >Seleccione...</option>
  67.                         </select>

Última edición por Triby; 04/11/2016 a las 19:50 Razón: Código en highlight