Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery validation with Textbox naming on ASP.NET MVC page?
    primarykey
    data
    text
    <p>I have two Textbox controls on my view. Here jQuery validation function is working when the name is one word. It is not working when the name is having any dots in it.</p> <p>In the below jQuery function, if I use "<strong><em>lastname</em></strong>" textbox id for validation, it is not allowing any other keys except digits. But somehow if I use "<strong><em>AddressDetail.ZipCode</em></strong>" textbox id to allow only digits, it is not calling. I have to use only "AddressDetail.ZipCode" as it is referencing the child table.</p> <p>Here is my code. </p> <pre><code>&lt;table&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td class="Form_Label"&gt;&lt;label for="LastName"&gt;Last Name&lt;/label&gt;&lt;em&gt;*&lt;/em&gt;&lt;/td&gt; &lt;td CssClass="Form_Value"&gt;&lt;%= Html.TextBox("lastname", Model.LastName, new { @class = "required", size = "30" })%&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td class="Form_Label"&gt;&lt;label for="Zip"&gt;Zip&lt;/label&gt;&lt;em&gt;*&lt;/em&gt;&lt;/td&gt; &lt;td CssClass="Form_Value"&gt;&lt;%= Html.TextBox("AddressDetail.ZipCode", Model.AddressDetail.FirstOrDefault().ZipCode, new { @class = "required zip", minlength = "5"})%&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td colspan="2" align="center"&gt;&lt;input type="submit" id="btnUpdProfile" value="Update" /&gt; &lt;/td&gt;&lt;/tr&gt; </code></pre> <p>JQuery function validation:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function() { //Disabling all other keys except digits $('#AddressDetail.ZipCode').live('keypress', function(e) { var keyPressed; if ((e.charCode) &amp;&amp; (e.keyCode == 0)) keyPressed = e.charCode else keyPressed = e.keyCode; if (keyPressed &lt; 48 || keyPressed &gt; 57) { return false; } return true; }); }); &lt;/script&gt; &lt;/tbody&gt; &lt;/table&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. 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