-
Notifications
You must be signed in to change notification settings - Fork 0
/
formvalidation.html
executable file
·51 lines (50 loc) · 1.39 KB
/
formvalidation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Form Validation</title>
<link rel="stylesheet" href="">
<script>
function validate() {
var x=document.myform.name.value;
var y=document.myform.pass.value;
if(x==="" || x===null){
document.getElementById('nA').innerHTML="ENTER NAME PLEASE";
document.getElementById('nA').style.color="red";
}else if(y==="" || y===null){
document.getElementById('pA').innerHTML="ENTER PASSWORD PLEASE";
document.getElementById('pA').style.color="red";
}else{
document.myform.submit();
}
}
</script>
</head>
<body>
<form name="myform" method="get" action="#">
<fieldset>
<legend>Login Details</legend>
name:
<input type="text" name="name" />
<span id="nA"></span>
<br>
password:
<input type="password" name="pass" />
<span id="pA"></span>
<br/>
</fieldset>
<fieldset>
<legend>Account</legend>
<input type="radio" name="account" value="admin"/>Admin Account<br>
<input type="radio" name="account" value="user"/>User Account<br>
<input type="radio" name="account" value="guest"/>Guest Account<br>
</fieldset>
<fieldset>
<legend>Hobbies</legend>
<input type="checkbox" name="hobbies" value="singing"/>Singing<br/>
</fieldset>
<input type="button" value="submit" onclick="validate()"/>
</form>
</body>
</html>