0

I need to validate if the entered value of intervalDuration is less than testDuration, but after couple of hours of searching I still was not found any solution which works for me.

I’m using the jQuery validation library.

Please help me.

var $val = jQuery.noConflict();

$val(document).ready(function() {
    $val("#uniformDistribution").validate({
        highlight: function(element) {
            $val(element).closest('.form-group').removeClass('has-success').addClass('has-error');
        },
        unhighlight: function(element) {
            $val(element).closest('.form-group').removeClass('has-error').addClass('has-success');
        },
        errorElement: 'span',
        errorClass: 'help-inline',
        rules: {
            testDuration: {
                required: true,
                digits: true,
                min: 1,
            },
            intervalDuration: {
                required: true,
                number: true,
                max: "#testDuration",
            },
        },
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="form-control" name="testDuration" id="testDuration" placeholder="Test duration" required>
<input type="text" class="form-control" name="intervalDuration" id="intervalDuration" placeholder="Interval duration" required>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
Marko
  • 1
  • http://stackoverflow.com/questions/1260984/jquery-validate-less-than – Sudharsan S Apr 11 '15 at 09:32
  • https://forum.jquery.com/topic/jquery-validate-of-2-dependant-input-fields – Sudharsan S Apr 11 '15 at 09:32
  • Why I would write my own method if jQuery validation library has max paramether, I just need to compare it with entered value in textbox before ... but max: "#testDuration" that rule does not work. Why? – Marko Apr 11 '15 at 09:40
  • I just wanted to note that some browsers might have [problems with trailing commas in object literals](http://stackoverflow.com/questions/5036618/does-internet-explorer-9-choke-on-extra-commas-at-the-end-of-array-and-object-li). – Sebastian Simon Apr 11 '15 at 09:46

0 Answers0