Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate dropdownlist using jquery
    primarykey
    data
    text
    <p>I have a registration form which uses one of jquery plugin for client side validation. I can validate textboxes and other controls but I have a problem with dropdownlist. I have a field on registration page</p> <pre><code>&lt;asp:DropDownList ID="ddlSector" runat="server" class="validateCallback my_code_callback"&gt;&lt;/asp:DropDownList&gt; </code></pre> <p>Those dropdown list outputs that</p> <pre><code>&lt;select name="ddlSector" class="validateCallback my_code_callback"&gt; &lt;option value="244"&gt;--Choose--&lt;/option&gt; &lt;option value="27"&gt;Hotel&lt;/option&gt; &lt;option value="28"&gt;Motel&lt;/option&gt; &lt;option value="29"&gt;Cottage&lt;/option&gt; &lt;/select&gt; </code></pre> <p>and I have such implementation on master template</p> <pre><code>&lt;script type="text/javascript" src="/scripts/uni-form-validation.jquery.js" charset="utf-8"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function () { $('form.uniForm').uniform({ prevent_submit: true }); }); window.my_code_callback = function (field, caption) { if (field.val() === '244') { return false; } } &lt;/script&gt; </code></pre> <p>in jquery file which does validation has such example</p> <pre><code> /** * Callback validator * * Lets you define your own validators. Usage: * * &lt;input name="myinput" class="validateCallback my_callback" /&gt; * * This will result in UniForm searching for window.my_callback funciton and * executing it with field and caption arguments. Sample implementation: * * window.my_callback = function (field, caption) { * if (field.val() === '34') { * return true; * } else { * return caption + ' value should be "34"'; * } * } * * @param jQuery field * @param caption */ validateCallback : function (field, caption) { var classes = field.attr('class').split(' '), callback_function = ''; for (var i = 0; i &lt; classes.length; i += 1) { if (classes[i] === 'validateCallback') { if (classes[i + 1] != 'undefined') { callback_function = classes[i + 1]; break; } } } if (window[callback_function] != 'undefined' &amp;&amp; (typeof window[callback_function] === 'function')) { return window[callback_function](field, caption); } return i18n('callback', caption, callback_function); } }; </code></pre> <p>How could I change the code so if visitor leaves the option --Choose--, it should display the error like other controls?</p>
    singulars
    1. This table or related slice is empty.
    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. 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