I want to get select value after I change it but it’s not working (even responding).
const sortSelect = document.getElementById("sortSelect");
function sortData() {
console.log(sortSelect.selectedOptions[0].value);
}
<select onchange="sortData();" id="sortSelect" class=" border border-gray-300 bg-gray-50 p-[.5rem] pl-[2rem] cursor-pointer rounded-xl text-[16px] focus:ring-gray-300 focus:border-gray-400 w-[16rem]" name="sortSelect">
<option>جدیدترین</option>
<option>قدیمی ترین</option>
<option>بیشترین زمان</option>
<option>کمترین زمان</option>
</select>
2
Answers
HTML:
JS:
This should return the (text) value of the selected option
Try with this code:
I change the value to 1,2,3,4 but the concept is the same.
It also semed like yuor snippet worked.