-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment-3(post).html
More file actions
68 lines (59 loc) · 2.06 KB
/
Copy pathassignment-3(post).html
File metadata and controls
68 lines (59 loc) · 2.06 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.mystyle {
border:2px solid red;
}
</style>
</head>
<body>
<form>
<label for="email">E-mail</label><br>
<input type="text" id="email" name="email"><br>
<label for="password">Password</label><br>
<input type="password" id="password" name="password"><br>
</form>
<button onclick="submit()">submit</button>
<script>
var email= document.getElementById('email');
function submit(){
console.log("name is blurred");
let regex = /^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/;
let mail = email.value;
console.log(regex,mail);
if(regex.test(mail)){
console.log('matched');
document.getElementById("email").classList.remove("mystyle");
post();
}
else{
console.log('no match');
document.getElementById("email").classList.add("mystyle");
}
}
function post()
{
var object= new XMLHttpRequest();
object.open("POST", "https://reqres.in/api/login", true);
object.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
object.send(`email=${email.value}&password=${password.value}`);
object.onreadystatechange =function()
{
if(this.readyState == 4 && this.status == 200){ //this code from w3 schools
var obj = JSON.parse(this.responseText);
console.log(obj);
alert("Successful", obj);
}
else if(this.readyState == 4 && this.status != 200){
alert("Please enter correct credentials");
}
}
}
</script>
</body>
</html>