-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (31 loc) · 1.06 KB
/
script.js
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
var form =document.getElementById("form");
var userName =document.getElementById("userName");
var email=document.getElementById("Email");
var currentPassword= document.getElementById("currentPassword");
var newPassword= document.getElementById("newPassword");
function showErrorMessage(input,message){
const formControl=input.parentElement;
formControl.className="form-control error";
const errorElem=formControl.querySelector("small");
errorElem.innerText=message;
}
function showSuccessMessage(input){
const formControl=input.parentElement;
formControl.className="form-control success";
}
function checkRequiredField(inputs){
for(var i=0;i<inputs.length;i++){
var input=inputs[i];
if(input.value===""){
const message=input.Id+" is required";
showErrorMessage(input,message);
}
else{
showSuccessMessage(input);
}
}
}
form.addEventListener('Submit',function(event){
event.preventDefault();
checkRequiredField(userName,email,currentPassword,newPassword);
})