Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're already using jQuery, you may be able to get approval to user the jQuery Validation plug-in, since it comes standard with Microsoft MVC applications now whenever you start a new project. That being said, I do recognize how hard it can be to get plug-ins approved, since I'm supporting different government clients. It looks like you could add a tag with each input element, and then modify the class for that span to show and hide it, similar to what you already do when highlighting the input box.</p> <p>I can't test this on my work machine, but I would think it's something like:</p> <pre><code>$(function () { $("#Save").click(Validate); }); function Validate() { var invalidValues = []; var validValues = []; var Code = $("#Code").val(); var Description = $("#Description").val(); var Status = $("#Status ").val(); var requiredFields = { '#Code' : Code, '#Description' : Description, '#Status ' : Status }; $.each(requiredFields, function (key, value) { if (value.length == 0) { invalidValues.push(key); } else { validValues.push(key); } }); var invalidFields = invalidValues.toString(); var validFields = validValues.toString(); if (invalidValues.length &gt; 0){ $(invalidFields).addClass("highlighted"); $(validFields).removeClass("highlighted"); $(invalidFields + "Validator").addClass("showValidation"); $(invalidFields + "Validator").removeClass("hideValidation"); return false; } $(validFields).removeClass("highlighted"); $(validFields + "Validator").removeClass("showValidation"); $(invalidFields + "Validator").addClass("hideValidation"); } </code></pre> <p>With the HTML</p> <pre><code>&lt;div&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt; Code &lt;/th&gt; &lt;td&gt; &lt;input maxlength="4" id="Code" type="text"/&gt;&lt;span id="CodeValidator" class="hideValidation" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; Description &lt;/th&gt; &lt;td&gt; &lt;input id="Description" type="text"/&gt;&lt;span id="DescriptionValidator" class="hideValidation" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; Status &lt;/th&gt; &lt;td&gt; &lt;input id="Status" type="text"/&gt;&lt;span id="StatusValidator" class="hideValidation" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; &lt;/th&gt; &lt;td&gt; &lt;button id="Save" type="button"&gt;Save&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre>
    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.
    1. VO
      singulars
      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