jQuery validate dependancy call function

Joppo

The following jQuery validate code is supposed to check the form that the user must enter the e_usage field if the e_usagelow field has not been filled in. I wrote the dependency call function for e-usage based on the example at jQuery Validation - Two fields, only required to fill in one, but somehow my function doesnt work (e.g. when putting the mouse on the e-usage field while e_usagelow is empty no validation-error warning appears and the console shows the value 'true')

What goes wrong?

Please your help.

html code:

E-usage: <input id="e_usage" type="text" name="e_usage">
E-usage low: <input id="e_usagelow" type="text" name="e_usagelow" >

javascript code:

$(document).ready(function () {
  $("#myForm").validate({
    rules: {
      'e_usage': {
        required: function (element) {
          console.log("validation: required: " + $("#e_usagelow").is(':empty'));
          return $("#e_usagelow").is(':empty');
        },
        minlength: 3,
        maxlength: 8,
        number: true
      },
      'e_usagelow': {
        required: true,
        minlength: 3,
        maxlength: 8,
        number: true
      }
    } //rules
  }); //validate()
}); //function
Tushar Gupta - curioustushar

DEMO

change 'e_usage' to e_usage

and 'e_usagelow' to e_usagelow

id is not enclosed in quotes

$(document).ready(function () {

    $("#myForm").validate({

        rules: {
            e_usage: { //removed quotes from id
                required: function (element) {
                    console.log("validation: required: " + $("#e_usagelow").is(':empty'));
                    return $("#e_usagelow").is(':empty');
                },
                minlength: 3,
                maxlength: 8,
                number: true
            },

            e_usagelow: { //removed quotes from id
                required: true,
                minlength: 3,
                maxlength: 8,
                number: true
            }

        } //rules


    }); //validate()

});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

jQuery Validate Script Error, Cannot read property call of undefined

분류에서Dev

jquery second function call not working

분류에서Dev

Call function within autocomplete jQuery plugin

분류에서Dev

Call jquery function when <ul> content change

분류에서Dev

Jquery ajax call inside success function

분류에서Dev

why cannot recursively call function in jquery?

분류에서Dev

jQuery - how to call method/prototype function

분류에서Dev

How call a Jquery function in the OnClick event?

분류에서Dev

cant call a javascript function within jquery

분류에서Dev

Angular.js call jquery function in Directive

분류에서Dev

How jquery can call a function in the 'end' of another?

분류에서Dev

How do I call a jQuery function on several jQuery objects?

분류에서Dev

How to validate a textbox in jQuery

분류에서Dev

How to call jquery function from @Html.ActionLink param routeValues

분류에서Dev

How can I automatically call a function on load in JQuery?

분류에서Dev

How do i send parameter in ajax function call in jquery

분류에서Dev

Understanding dependancy objects

분류에서Dev

jquery validation is not working with validate plugin

분류에서Dev

Using jQuery validate rule twice for a field

분류에서Dev

jQuery Validate 플러그인, if 문

분류에서Dev

jQuery Validate로 equalTo 검증

분류에서Dev

jquery Validate errorPlacement insert element + br + error

분류에서Dev

jQuery .validate () 및 양식 제출

분류에서Dev

jQuery Validate form check if date is specific day

분류에서Dev

Undefined Function Call

분류에서Dev

Call functions in a function in prolog

분류에서Dev

How to call to function

분류에서Dev

Call function in document insert

분류에서Dev

Matlab Substring as function call?

Related 관련 기사

뜨겁다태그

보관