function checkAge()
{
var age = document.getElementById('a');
if(age.value >= 1 && age.value <=17)
{
alert("you are a minor");
}
else{
alert("you are an adult")
}
}
input {
border:solid 2px
}
input:valid {
border:solid 2px;
border-color:blue;
}
input:invalid{
border:solid 1px;
border-color:red;
}
<link rel="stylesheet" type="text/css" href="style1.css"/>
<script type="text/javascript" src="script1.js"></script>
</head>
<body>
<form action="process.php" method="post">
First name : <input type="text" name="fname" autofocus />
<br/>
Age : <input type="number" name="age" id="a" max="100" min="0"/>
<br/>
Email : <input type="email" name="email" required/>
<br/>
Order id: <input type="text" name="order" pattern="[0-9]{2}{A-Z}{3}" title="2 digits and then 3 letters"/>
<br/>
Password : <input type="password" name="pass" required/>
<br/>
<input type="submit" value="send" onclick="checkAge()"/>
</form>

Post a Comment