Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery selector with ASP.NET controls
    primarykey
    data
    text
    <p>iam using ajax in asp.net page for state, city and zip code field. i want this ajax functionality to be generic. i want to use the same ajax functionality for the textbox and label controls with different ids. i tried with cssclassproperty but it applied to both set of controls. the code is following below</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function () { $('.csszipcode').blur(function (event) { var text = $('.csszipcode').val(); if (text == "") { $('.csslblcity').text(""); $('.csslblstate').text(""); return; } var isValid = /^[0-9]{5}(?:-[0-9]{4})?$/.test(text); if (!isValid) { $('.csslblcity').text(""); $('.csslblstate').text(""); return; } $.ajax({ type: "POST", url: "/SERVICES/DataService.asmx/getCityState", data: "{'zipcode': '" + $('.csszipcode').val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { AjaxSucceeded(msg); }, error: AjaxFailed }); }); }); function AjaxSucceeded(result) { var city = result.d.split(':')[0]; var state = result.d.split(':')[1]; if (city != null &amp;&amp; state != null) { $('.csslblcity').html(city); $('.csslblstate').html(state); } else { $('.csslblcity').text(""); $('.csslblstate').text(""); } } function AjaxFailed(result) { alert(result.status + ' ' + result.statusText); } &lt;/script&gt; </code></pre> <p>the html codes are following. i want to apply the ajax functionality for the following two textboxes. how can i differentiate which is currently active.</p> <pre><code>&lt;asp:textbox id="txtzipcode" runat="server" cssclass="csszipcode"&gt;&lt;/asp:textbox&gt; &lt;asp:textbox id="txtcandacode" runat="server" cssclass="csszipcode"&gt;&lt;/asp:textbox&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.
 

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