-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction fun().js
70 lines (63 loc) · 1.71 KB
/
function fun().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
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
69
70
function fun()
{
var name=document.getElementById("name");
var email=document.getElementById("email");
var contact=document.getElementById("mobile");
var ab = email.value.indexOf("@");
var bc = email.value.lastIndexOf(".");
if(name.value=="" || email.value=="" || contact.value=="")
{
window.alert("Enter the required field");
}
else if(name.value.length<3)
{
window.alert("Name must be 3 characters long");
}
else if(contact.value.length!=10)
{
window.alert("Enter valid Mob No");
}
else if(ab < 1 || ( bc - ab < 2 ))
{
window.alert("Enter valid Email-ID");
}
else
{
var dis=document.getElementById("output");
dis.style.display="block";
var table = document.getElementById("detailTable");
var count=0;
for (let row of table.rows)
{
for(let cell of row.cells)
{
if(cell.innerText == email.value || cell.innerText==contact.value)
count=1;
}
}
if(count==1)
alert("User already exists");
else
{
var row = table.insertRow(table.length);
row.setAttribute("class","table-success");
row.setAttribute("id","delRow")
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = name.value;
cell2.innerHTML = email.value;
cell3.innerHTML=contact.value;
cell4.innerHTML="<a href='#' onclick='del(delRow)'>Delete</a>";
name.value='';
email.value='';
contact.value='';
}
}
}
function del(delRow)
{
var table = document.getElementById("detailTable");
delRow.parentNode.removeChild(delRow);
}