Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/08/2011, 16:27
manuperetti
 
Fecha de Ingreso: mayo-2011
Mensajes: 11
Antigüedad: 12 años, 11 meses
Puntos: 1
No funciona el onchange en select

Hola a todos,
Estoy teniendo un problema y no puedo darme cuenta cual es el error. Cuando selecciono un valor del select se deberia ejecutar una funcion javascript pero por alguna razon esto no sucede.

Este es el codigo html:
Código:
<tr>
   <td width="50">Vehiculo:</td>
   <td width="50">
   <select id="nmvehiculo" style="background-color: #ffffa0" name="nmvehiculo" onChange="func_fecha(this.value)">
   <option value="vacio">Seleccionar vehiculo</option>

<?php while($row=mysql_fetch_array($result)) { ?>
<option value="<?php echo $row['ID'];?>"><?php echo $row['vehiculo'];?></option>
<?php } ?>

  </select></td>
</tr>
<tr>
  <td><br>Fecha:</td>
  <td>
  <div id="fechadiv">
  <br />
   <select style="background-color: #ffffa0" name="nmfecha" onChange="func_cond(this.value,document.getElementById('nmvehiculo').value)">
  <option value="vacio">Debe seleccionar vehiculo</option>       
  </select>
  </div>
  </td>
</tr>
Hay un poco de PHP pero es solo para llenar el primer select.
El primer select funciona bien al igual que la funcion "func_cond()", probe todo en firefox y observando con el firebug.

Si sirve de algo, la funcion en javascript es:
Código:
function func_cond(fecha, id_vehiculo) {		
		alert("Llamada a funcion conductor");		
		var strURL="getconductor2.php?fecha="+fecha+"&id_vehiculo="+id_vehiculo;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('conddiv').innerHTML=req.responseText;						
					} else {
						alert("Ocurrio un problema usando XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
Si ejecuto la funcion func_cond desde el firebug, el select dentro del div "conddiv" se llena correctamente (con AJAX). Es por eso que creo que hay algun error con el segundo select.
Cualquier ayuda se agradece.

Última edición por manuperetti; 12/08/2011 a las 16:35