I have written a html code for two dropdown boxes. I want to pass these two values as a parameters to a javascript function when we change the second dropdown (onchange).
Here is my code:
function CatName(str1, str2) {
if (str == "") {
document.getElementById("album_name").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("album_name").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "update.php?q=" + str1 + "&q1=" + str2, true);
xmlhttp.send();
}
}
<div class="col-xs-6 col-sm-6 col-md-4 col-md-offset-1">
<div class="form-group">
<select class="form-control" name="category_name">
<option value="" selected>Please Select</option>
<option value="Birds">Birds</option>
<option value="Notinlist">Category Not in list</option>
</select>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-4 col-md-offset-1">
<div class="form-group">
<select class="form-control" name="album_name" onchange="CatName(this.value)">
<option value="" selected>Please Select</option>
<option value="Dove">Dove</option>
<option value="Parrot">Parrot</option>
<option value="Notinlist">Category Not in list</option>
</select>
</div>
</div>
CatName(this.value, document.getElementById("id-of-the-first-select-box-here").value);