0

I want cancel change event when selected item compare with another select list value. I have 2 selectlist.I want when #SecondUnit_Id changed execute below function but does not work.

var preval=$('#SecondUnit_Id').val();

$('#SecondUnit_Id').change(function(){
  
  if($(this).val()==$('#UnitList_Id').val())
    {
       msgbox("error","Duplicate");
       $(this).val(preval);
       return false;
    
    }
    
    preval=$(this).val();
  
  });

But Does Not Work below code:

$(this).val(preval)
Mohsen Zahedi
  • 651
  • 2
  • 10
  • 28

1 Answers1

1

Its Working For me

Working Demo

<select id="UnitList_Id">
<option>A</option>
<option>B</option>
<option>C</option>
</select>


<select id="SecondUnit_Id">
<option>A</option>
<option>B</option>
<option>C</option>
</select>

var preval=$('#SecondUnit_Id').val();
alert(preval)
$('#SecondUnit_Id').change(function(){
  //alert($('#UnitList_Id').val())
  if($(this).val() === $('#UnitList_Id').val())
    {
       alert("error Duplicate");
       $(this).val(preval);
       return false;

    }

    preval=$(this).val();

  });

The problem is in your msgbox pluggin . Use the related library properly.

Amar Singh
  • 5,464
  • 2
  • 26
  • 55