Comunidad de diseño web y desarrollo en internet online

No se como salir de este problema

Citar            
MensajeEscrito el 01 May 2011 10:44 pm
Estoy practicando javascript pero me quede en un ejercicio.

Crear un formulario con tres botones con las leyendas "1", "2" y "3". Mostrar un mensaje indicando qué botón se presionó.

yo hice lo siguiente:

Código :


<script type="text/javascript">



function funcion(){
   
   if(document.form1.boton1.value){
      alert('boton1');
      
     }else if(document.form1.boton2.value){
        alert('boton2');
        }else if(document.form1.boton3.value){
           alert('boton3');
           }
   
}


</script>
</head>

<body>

<form name="form1" method="post">
<input type="button" onclick="funcion();" name="boton1" value="boton" />
<input type="button" onclick="funcion();" name="boton2" value="boton2" />
<input type="button" onclick="funcion();" name="boton3" value="boton3" />







</form>





a cualquier boton que le haga click, me tira el alert del boton1.
No se por que...

Muchas gracias.

Por yoelotero

51 de clabLevel



Genero:Masculino  

Programador web.

chrome
Citar            
MensajeEscrito el 02 May 2011 02:44 am
lo logré de esta forma, pero no es la que yo busco igual.



<form name="form1" method="post">
<input type="button" onclick="alert('boton1');" name="boton1" value="boton" />
<input type="button" onclick="alert('boton2');" name="boton2" value="boton2" />
<input type="button" onclick="alert('boton3');" name="boton3" value="boton3" />







</form>

Por yoelotero

51 de clabLevel



Genero:Masculino  

Programador web.

chrome
Citar            
MensajeEscrito el 02 May 2011 03:00 pm

Código Javascript :

<script type="text/javascript">
function funcion(ele){
      alert(ele.name);
}
</script>
</head>

<body>

<form name="form1" method="post">
<input type="button" onclick="funcion(this);" name="boton1" value="boton" />
<input type="button" onclick="funcion(this);" name="boton2" value="boton2" />
<input type="button" onclick="funcion(this);" name="boton3" value="boton3" />
</form>

Por DriverOp

Claber

2510 de clabLevel



 

opera

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.