Note that there are some explanatory texts on larger screens.

plurals
  1. POConditional validation of text boxes in ASP.NET user control using jQuery validation plugin
    primarykey
    data
    text
    <p>In my ASP.NET user control I have 3 text boxes that I'm validating using jQuery but I'm having some problems getting the validation to function the way I need it to. The text boxes are for a first name, last name and company name and what I would like to do is if the first name and last name are entered, the company name is no longer required. If a company name has been entered, the first and last name are no longer required.</p> <p>I have it partially working but the problem is when the first and last name text boxes are populated the company name still shows as being required and the same happens when the company name is populated, the first and last name still shown as being required. I'm at a loss as to how I can acheive what I outlined above, I'm rather new to jquery which doesn't help either. Here is my code so far:</p> <pre><code>$(document).ready(function () { var firstNameCtrl = $('#&lt;%= addressInfo.FirstNameClientID %&gt;'); var lastNameCtrl = $('#&lt;%= addressInfo.LastNameClientID %&gt;'); var companyNameCtrl = $('#&lt;%= addressInfo.CompanyClientID %&gt;'); firstNameCtrl.focus(); $('form').validate({ highlight: function (element, errorClass) { $(element).addClass("invalidElem"); }, unhighlight: function (element, errorClass) { $(element).removeClass("invalidElem"); }, errorElement: "div", errorClass: "errorMsg" }); $.validator.addClassRules({ nameValidation: { required: { depends: function (element) { return ($(companyNameCtrl).val() == ''); } //end depends } //end required }, //end nameValidation companyValidation: { required: { depends: function (element) { return ($(firstNameCtrl).val() == '' &amp;&amp; $(lastNameCtrl).val() == ''); } } } }) $(firstNameCtrl).add(lastNameCtrl).add(companyNameCtrl).addClass("nameValidation").change(function (e) { $('form').validate().element($(e.target)); }); $(companyNameCtrl).addClass("companyValidation").change(function (e) { $('form').validate().element($(e.target)); }); }); //end ready </code></pre> <p>Hope my question makes sense. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload