Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Validation only validating the first hidden input element?
    text
    copied!<p>I have two hidden input fields on my form that I have linked to jquery validation rules. These are sort of "global" form rules (for example the total of multiple fields not equal to 100%), so I am using hidden fields at the top of my form to show a message that applies to the whole form.</p> <p>They are defined like this:</p> <pre><code>&lt;input type="hidden" class="futuretotalsunder"/&gt; &lt;input type="hidden" class="futuretotalsrequired"/&gt; </code></pre> <p>Here are my rule definitions. You can get the idea of it. The first rule checks to see if a bunch of text boxes total up to &lt; 100, and the second check to make sure the total isn't 0. The problem is, the only one that fires is whichever one is applies to the first hidden input element. The second one never fires. Any idea why?</p> <pre><code>$.validator.addMethod("futuretotalsunder", function (val, element, params) { alert("under"); var total = 0; $(".TransferPercentTextBox").each(function () { total = total + parseInt($(this).val()); }); if ((total &lt; 100) &amp;&amp; (total != 0)) { window.location.href = "#Top"; return false; } else { return true; } }, "Total percentage must equal 100%."); $.validator.addMethod("futuretotalsrequired", function (val, element, params) { var total = 0; $(".TransferPercentTextBox").each(function () { total = total + parseInt($(this).val()); }); if (total == 0) { window.location.href = "#Top"; return false; } else { return true; } }, "Transfer amount must be greater than 0."); </code></pre>
 

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