I am working in a legacy application where I am in the obligation of getting the value of an option by the option text instead of the other way like usual.
Here is a non working example that I need help with
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
</head>
<body>
<select id="myselect" name="myselect">
<option value="0">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<script>
$(document).ready(function(){
var optionText = 'Two';
console.log($('#myselect option[option="' + optionText + '"]').attr("value"));
});
</script>
</body>
</html>
Thanks