I'm making three dropdowns on HTML and I make a JavaScript program to alert when there has a duplicate selected value. What should I do If after the alert the selected dropdown return its default value after the alert.
function hey() {
var count = document.getElementsByClassName('data').length;
//var cars = document.getElementsByClassName('data')[0].value;
var arr = [];
var text = "";
var i = 0;
while (i < count) {
if ((document.getElementsByClassName('data')[i].value) == "") {} else {
arr.push(document.getElementsByClassName('data')[i].value);
}
i++;
}
document.getElementById("demo").innerHTML = arr;
var uniqueval = arr.filter(function(itm, i, arr) {
return i == arr.indexOf(itm);
});
if (arr.length > uniqueval.length) {
alert("Has duplicate")
}
}
<div class="info">
<select name="type" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<select name="class" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<select name="class" class="data" onchange="hey()">
<option value="">---select---</option>
<option value="teacher">Teacher</option>
<option value="student">Student</option>
<option value="students">Students</option>
</select>
<p id="demo"></p>
</div>
<p>When I select another dropdown and its been already selected <br>
Theres have an alert message and when I click OK I want to return its default value which is --select--</p>
I want to return the --select-- value after the alert of the selected dropdown.