How Can I get 2 different select values at single time ,so I can use both of them in conditions at a single time
$(document).ready(function() {
$('#select_w').on('change', function() {
var a = $('#select_w').find(":selected").text();
}
$('#select_s').on('change', function() {
var b = $('#select_w').find(":selected").text();
}
//condition
if (a == "area" && b == "circle") {
//aread of circle
}
if (a == "area" && b == "square") {
//area of square
}
if (a == "volume" && b == "square") {
//volume of square
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select class="form-control" id="select_w" name="op">
<option value="select">---Select Value---</option>
<option value="area">Area</option>
<option value="volume">Volume</option>
</select>
<select class="form-control" id="select_s" name="shapes">
<option value="select">---Select Value---</option>
<option value="circle">Circle</option>
<option value="square">Square</option>
</select>
How can I use the var outside the function? Or is there any other approach in which i can get both select values on change and can perform operation according to the received values