jQuery Validation plugin - Custom method comparing two select dropdowns

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.

Answers


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;

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;
}

Need Your Help

I receive method options and return undefined

json angularjs http login put

I'm writing my login form which provides for a put request to the server.

Mac app is still running after deleting Info.plist

osx bundle info.plist

I want to build a Mac App from scratch. I manually created the required folders of main app, Contents, MacOS, Resources, and dropped the binaries. The only one I don't know how to create from scrat...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.