En el curso de Javascriptya.com se plantea este ejercicio de formularios:
"Crear un formulario con tres botones con las leyendas "1", "2" y "3". Mostrar un mensaje indicando qué botón se presionó"
Y la solución ofrecida por la misma web es la siguiente:
<script type="text/javascript">
function presion1()
{
alert('Se presionó el botón 1');
}
function presion2()
{
alert('Se presionó el botón 2');
}
function presion3()
{
alert('Se presionó el botón 3');
}
</script>
<form>
<input type="button" onClick="presion1()" value="Boton 1">
<input type="button" onClick="presion2()" value="Boton 2">
<input type="button" onClick="presion3()" value="Boton 3">
</form>
Me quedo un poco desconcertado... ¿hay que crear tantas funciones como botones, no existe otra opción?
Gracias por la ayuda, un saludo.