<html> <head> <script> function validateForm() { var x = document.forms["myform"]["txtname"].value; if (x == null || x=="") { aleart ("please enter the name"); return false; } } </script> </head> <body> <form name="myform" action="demo.php"> Name <input type ="text" name= "txtname"><br /> <input type="submit" value ="Submit"> </form> </body> </html>
alert
aleart
<form name="myform" action="#" onSubmit="return validateForm();">
<html> <head> <script> function validateForm() { var x = document.forms["myform"]["txtname"].value; if (x == null || x=="") { alert ("please enter the name"); return false; } } </script> </head> <body> <form name="myform" action="demo.php" onSubmit="return validateForm();"> Name <input type ="text" name= "txtname"><br /> <input type="submit" value ="Submit"> </form> </body> </html>
<html> <head> <script> function validateForm() { var x = document.getElementById("txtname").value; if (x == null || x=="") { alert ("please enter the name"); return false; } } </script> </head> <body> <form name="myform" action="demo.php" onSubmit="return validateForm();"> Name <input type ="text" name= "txtname" id="txtname"><br /> <input type="submit" value ="Submit"> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)