Prev Demo
JavaScript
>
How To Execute A Function When Html Form Is Submitted In Javascript?
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Onsubmit</h1> <form action="Alert.htm" method="post" onsubmit="return CallFunction()"> Enter your name: <input type="text" name="txtName" id="txtName" /> <input type="submit" id="btn" name="btn" value="Submit" /> <script> function CallFunction() { if (document.getElementById("txtName").value == "itfunda") { return true; } else { alert("Write \"itfunda\" in the textbox"); return false; } } </script> </form> <p><strong>Note: </strong> Write some text and click the button, so that you will get an alert with the content what you need to write in the text box.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output