单位转换验证双向

时间:2015-04-22 11:55:39

标签: jquery

我正在进行单位转换项目,我正在转换像KG =>这样的单位。 GRAM或KG => TON等我必须设置验证,以便一旦选择转换单位(例如(KG => GRAM))它就不允许用户转换(GRAM => KG)

这是我的代码:

<select onchange="checkDuplicateUnitConversion(this,0,'to');" class="to-unit0" name="toUnit">
    <option value="1">kilogram</option>
    <option value="2">gram</option>
</select>

JS CODE

function checkDuplicateUnitConversion(element,row,type)
{
       $("select").each(function(index){        
       });

    switch(type)
    {
        case 'from':
           $("select[name='fromUnit']").each(function(index){
               if(this.value===$('.to-unit'+index).val()){
                           alert("Select Valid Units");
                            $('#addMoreUnitConversion').prop('disabled', true);
                 }
                 else{
                      $('#addMoreUnitConversion').prop('disabled', false);
                 }
           });
        break;

        case  'to':
           $("select[name='toUnit']").each(function(index){

               if(this.value===$('.from-unit'+index).val()){
                           alert("Select Valid Units");
                                $('#addMoreUnitConversion').prop('disabled', true);
                 }
                   else{
                      $('#addMoreUnitConversion').prop('disabled', false);
                 }
           });
        break;    
    }
}

enter image description here

0 个答案:

没有答案