This is a select & option in HTML. I use jQuery here. I need to fetch the value of both select and pass the values to ajax.php where I need to use both values to check in my database and proceed with another dependent dropdown.
<label>Select Number: </label>
<select id= "number" onchange="FetchState(this.value)" required>
<option value="0">-- 0 --</option>
<option value="1">-- 1 --</option>
<option value="2">-- 2 --</option>
<option value="3">-- 3 --</option>
</select>
<label>Select letter: </label>
<select id="alphabet" required>
<option value="a">-- a --</option>
<option value="b">-- b --</option>
<option value="c">-- c --</option>
<option value="d">-- d --</option>
</select>
<select id="dependent">
</select>
This is my script code written below.
function FetchState(id) {
$("#dependent").html('');
$.ajax({
type: "POST",
url: "ajax.php",
data: {
number: id,
},
success: function(data) {
$("#dependent").html(data);
}
});
}
</script>
I need to pass two values to PHP via jQuery (ajax) to continue further. Here both letter and alphabet value should be get and pass as data in jQuery to ajax.php
2
Answers
What about declaring an array, pushing to it and then firing the ajax call when you have reached two items in the array?
The html is a little odd but as you will always have a selection in both dropdowns we could simply do
And if the dummy ajax_endpoint.php was this
It should fill the 3rd dropdown for you