Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay validation message
    primarykey
    data
    text
    <p>I am struggling with displaying validation messages on my webpage. I have a javascript function which does client side validation and highlights the fields with invalid values. Besides highlighting the fields, I want to display a message on my webpage which I dont know how to do.</p> <p>Here is my javascript function:</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"); return false; } $(validFields).removeClass("highlighted"); } </code></pre> <p>Here is my webpage:</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;/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;/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;/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> <p>I want to display a message at the bottom of my webpage saying "Please enter valid values for: Code". I store invalid values in a variable "invalidValues "in my js function "Validate" How can I access those values in my webpage?</p> <p>I also have a few questions about what is the best way of doing validations? Client side vs server side? also, is it better to display a pop-up validation message or a highlighted message embedded on webpage?</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