Form onsubmitEvento
Objeto Form
Definición y uso
El evento onsubmit se invoca al enviar el formulario.
Sintaxis
onsubmit="JavaScriptCode"
| Parámetros | Descripción |
|---|---|
| JavaScriptCode | Obligatorio. Especifica el código JavaScript a ejecutar después de que se active el evento. |
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales soportan el evento onsubmit
Ejemplo
Ejemplo
Cuando se hace clic en el botón de envío para enviar el formulario, se muestra un cuadro emergente:
<html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
Pruébalo »
Objeto Form Otras extensiones