Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/10/2011, 18:09
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Onclick en Select

onclick en option no funciona en todos los navegadores. Deberías usar onchange en el tag select.

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<
title>Untitled Document</title>
<
script type="text/javascript">
function 
f1(){alert(1)}
function 
f2(){alert(2)}
</script>
</head>

<body>
<form action="" method="get"><select name="" onchange="if(typeof window[this.value]=='function')window[this.value].call()">
<option value="0">seleccionar</option>
<option value="f1">uno</option>
  <option value="f2">dos</option>
</select></form>
</body>
</html> 
O así si necesitás argumentos:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<
title>Untitled Document</title>
<
script type="text/javascript">
function 
f1(a,b,c){alert(a+b+c)}
function 
f2(a,b){alert(a+b)}
var 
argumentos=[['w','x','y'],[1,2]];
</script>
</head>

<body>
<form action="" method="get"><select name="" onchange="if(typeof window[this.value]=='function')window[this.value].apply(null,argumentos[this.selectedIndex-1])">
<option value="0">seleccionar</option>
<option value="f1">uno</option>
  <option value="f2">dos</option>
</select></form>
</body>
</html> 

Última edición por Panino5001; 01/10/2011 a las 18:22