I have an select input field, and i have an onchange function. The table shows the value on the selected value, if nothing is selected, it should show all data. I want to know if it possible to get the value of that select field before the onchange happens? So, the value before the change.
I looked on the internet, but nothing helps.
This is my current code:
HTML
<form action="#" method="get">
<div class="form-group" style="max-width: 300px; width: 98%;">
<select name="status" id="status" class="form-control" onchange="getProjectsByStatus(this.value)">
<option value="">Select a status</option>
<?php foreach ($status as $stat) { ?>
<option value="<?php echo $stat['status_id']; ?>"><?php echo $stat['status']; ?></option>
<?php } ?>
</select>
</div>
</form>
Javasscript
function getProjectByStatus(value) {
var current = document.getElementById('project-status').value;
if (value == "") {
document.getElementById('project-status').innerText = this.current;
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById('project-status').innerHTML = this.responseText;
}
};
xmlhttp.open('GET', 'getProjectsByStatus.php?status='+value, true);
xmlhttp.send();
}
}