Skip to content Skip to sidebar Skip to footer

Javascript If Else Condition Not Working

I show a result after an 'if else' condition control selection. But I want show only one result if I change selected item in the second box. How can I solve this problem ? For Exa

Solution 1:

Hide the other control when you selected another :

functionCompare(sel1, sel2) {
  if (sel1 == 'A' && sel2 == '1') {
    $('#first').show();
    $('#second').hide();
    $('#first1').prop('disabled', false);
  } elseif (sel1 == 'A' && sel2 == '2') {
    $('#second').show();
    $('#first').hide();
    $('#second1').prop('disabled', false);
  }
}

var $sel1 = $("#sel1"),
    $sel2 = $("#sel2");


$("#sel1, #sel2").change(function() {
  Compare($sel1.val(), $sel2.val());
});

Solution 2:

You're showing elements, but never hide them again. You'll want to hide elements that you no longer wish to show, otherwise they will continue to display.

Post a Comment for "Javascript If Else Condition Not Working"