ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Show JavaScript alert if TextBox length greater than two on Button click in JavaScript<p>Hi <a class="username" rel="chetan"> chetan</a>,</p> <p>Change your code with the below code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;div class=&#34;header-input-container&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;span class=&#34;header-input-title&#34;&gt;Keyword:&lt;/span&gt; &nbsp;&nbsp;&nbsp; &lt;input type=&#34;text&#34; id=&#34;txtkeyword&#34; name=&#34;s&#34; runat=&#34;server&#34; autocomplete=&#34;off&#34;&gt;&lt;div &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class=&#34;clearfix&#34; /&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &lt;/div&gt; &lt;div class=&#34;header-input-container&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;span class=&#34;header-input-title&#34;&gt;Category:&lt;/span&gt; &nbsp;&nbsp;&nbsp; &lt;input type=&#34;text&#34; id=&#34;txtserach&#34; list=&#34;browsers&#34; name=&#34;myBrowser&#34; runat=&#34;server&#34; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; autocomplete=&#34;off&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;datalist id=&#34;browsers&#34;&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Automotive&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Building and Interiors&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Food, Kitchen and Hotel Supplies&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Industrial and Machinery&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Consumer and Household&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Medical and Healthcare&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Printing , Packaging and Plastic&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;IT / Telecom / Electronics&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Oil and Gas&#34;/&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;option value=&#34;Power and Energy&#34;/&gt; &nbsp;&nbsp;&nbsp; &lt;/datalist&gt; &nbsp;&nbsp;&nbsp; &lt;div class=&#34;clearfix&#34;&gt; &nbsp;&nbsp;&nbsp; &lt;/div&gt; &lt;/div&gt; &lt;asp:Button ID=&#34;Search&#34; class=&#34;dt-header-search-submit dt-button dt-button-danger&#34; &nbsp;&nbsp;&nbsp; Style=&#34;top: 0px; width: 226px; height: 70px;&#34; Text=&#34;Search&#34; runat=&#34;server&#34; OnClick=&#34;doit&#34; &nbsp;&nbsp;&nbsp; OnClientClick=&#34;return checkLength();&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; &nbsp;&nbsp;&nbsp; function checkLength() { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var textbox = document.getElementById(&#34;txtkeyword&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (textbox.value.length &lt; 3) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert(&#34;The entered input should be 3 or more than 3 characters&#34;); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return false; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp;&nbsp;&nbsp; } &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://i.imgur.com/6dCC6ey.gif" alt="" width="426" height="216" /></p>https://www.aspforums.net:443/Threads/577613/Show-JavaScript-alert-if-TextBox-length-greater-than-two-on-Button-click-in-JavaScript/https://www.aspforums.net:443/Threads/577613/Show-JavaScript-alert-if-TextBox-length-greater-than-two-on-Button-click-in-JavaScript/Mon, 08 Oct 2018 01:01:39 GMT