1

I have these two select type of HTML:

<label for="h_slat_type">Slat Type</label>
<select name="h_slat_type" id="h_slat_type">
                    <option disabled="disabled" selected>Select</option>
                    <option disabled="disabled">---------</option>
                    <option value="1">Type 1</option>
                    <option value="2">Type 2</option>
            </select>

<label for="v_slat_type">Slat Type</label>
<select name="v_slat_type" id="v_slat_type">
                    <option disabled="disabled" selected>Select</option>
                    <option disabled="disabled">---------</option>
                    <option value="1">Type 1</option>
                    <option value="2">Type 2</option>
            </select>

The condition for validation to fail is when I have both h_slat_type and v_slat_type set as 2.

In other words if:

h_slat_type 1 = v_slat_type 1 -> true

h_slat_type 2 = v_slat_type 1 -> true

h_slat_type 1 = v_slat_type 2 -> true

h_slat_type 2 = v_slat_type 2 -> false

The JS method:

jQuery.validator.addMethod("typecheck", function(value, element) {
    return ($('#h_slat_type').val() == $('#v_slat_type').val());
}, "Horizontal Type 2 and Vertical Type 2 incompatible!");

What would work in this case? ty vm.

1
  • I also tried return ($('#h_slat_type').val() + $('#v_slat_type').val()) == 4; but I don't get the expected result. Commented Dec 9, 2013 at 11:39

2 Answers 2

1

Try this:

    if($('#h_slat_type').val() == $('#v_slat_type').val())
       return true;
    else if ($('#h_slat_type').val()==1 && $('#v_slat_type').val()==2)
       return true;
    else if ($('#h_slat_type').val()==2 && $('#v_slat_type').val()==1)
       return true;
    else
       return false;
Sign up to request clarification or add additional context in comments.

2 Comments

ty vm, I had to change the first line before I could get the expected result : if($('#h_slat_type').val()==1 && $('#h_slat_type').val()==1)
The first If for both of your first and last condition ( 1==1, 2==2)
0

You can try the code below:

{
var selection_1 = $('#h_slat_type').val();
var selection_2 = $('#v_slat_type').val();
if(selection_1=='2' && selection_2=='2') return false;
return true;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.