-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.js
35 lines (32 loc) · 1.15 KB
/
hello.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
<html>
<head>
<script>
function fun() {
var country_list = ["ENGLAND", "US", "India", "Sri Lanka", "Nepal","Germany","UK"];
var country = document.getElementById("country").value;
if (country_list.includes(country)) {
var ul = document.getElementById("mylist");
var li = document.createElement("li");
li.appendChild(document.createTextNode(country));
ul.appendChild(li)
document.getElementById("error").style.visibility="hidden";
}
else{
alert("Enter a country name from this list \"ENGLAND\", \"US\", \"India\", \"Sri Lanka\", \"Nepal\"")
document.getElementById("error").style.visibility="visible";
}
}
</script>
</head>
<body>
<input type="text" placeholder="Enter country name" id="country" />
<input type="button" value="Add country" onclick="fun()" />
<div id="error" style="visibility: hidden;">
<p style="color: red;"> Please enter a valid county</p>
</div>
<div>
<ul id="mylist">
</ul>
</div>
</body>
</html>