Ronit Ronit - 3 months ago 5
Javascript Question

How to use multiple conditional in jquery? Use both IF OR in jquery

I am trying IF with OR in jquery but only "Returns" is working. "In Process" is not working. Help needed.

$('.target').change(function() {
if (($(this).find('option:selected').val() == 'Returns') || ($(this).find('option:selected').val() == 'In Process')) {
$(".answer").show('slow');
}
else{
$(".answer").hide('slow');
}
});

Answer

Use .val() to get the selected value of a select element. Have a look below, it's working perfectly fine

$('.target').change(function() {
     if ($(this).val() == 'Returns' || $(this).val() == 'In Process') {
       $(".answer").show('slow');
     }
     else{
         $(".answer").hide('slow');
     }
   });
.answer{
  height:50px;
  border:1px solid #333;
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="target">
  <option value="">select</option>
  <option value="Returns">Returns</option>
  <option value="In Process">In Process</option>
</select>
<br>
<div class="answer"></div>