-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
52 lines (44 loc) · 1.5 KB
/
test.php
File metadata and controls
52 lines (44 loc) · 1.5 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
<!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>
</head>
<body>
<form action="" method="post">
<select name="slct1" id="slct1" onchange = "populate(this.id, 'slct2')" >
<option value=""> -- choose option -- </option>
<option value="india">INDIA</option>
<option value="america">AMERICA</option>
</select><br><br>
<select name="slct2" id="slct2">
<option value=""></option>
</select>
</form>
<script>
function populate(s1,s2)
{
var s1 = document.getElementById(s1);
var s2 = document.getElementById(s2);
s2.innerHTML = "";
if(s1.value = "india")
{
var optionArray = ['delhi|Delhi', 'mumbai|Mumbai', 'bangalore|Bangalore'];
}else if(s1.value = "america")
{
var optionArray = ['newyork|Newyork', 'washington|Washington', 'houston|Houston'];
}
for(var option in optionArray)
{
var pair = optionArray[option].split("|");
var newoption = document.createElement("option");
newoption.value = pair[0];
newoption.innerHTML = pair[1];
s2.options.add(newoption);
}
}
</script>
</body>
</html>