Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:26:30+00:00 2026-05-28T07:26:30+00:00

I have this blur function as shown below and on first time it dosen’t

  • 0

I have this blur function as shown below and on first time it dosen’t check and when text changed for the second time it works

<script type = "text/javascript">
    function ShowAvailability() {
    var userName = $("#<%=txtUsername.ClientID %>");
    $("#<%=txtUsername.ClientID %>").blur(function () {
        userName = $(this).val();

        if (userName.length < 5) {
            $("#mesg")[0].innerHTML = "";
        }
        else {
            $.ajax({
                type: "POST",
                url: "Default.aspx/CheckUserName",
                data: '{userName: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response);
                }
            });
        }
    });
    }
    function OnSuccess(response) {
        var mesg = $("#mesg")[0];

        switch (response.d) {
            case "true":
                mesg.style.color = "green";
                mesg.innerHTML = "Available";
                break;
            case "false":
                mesg.style.color = "red";
                mesg.innerHTML = "Not Available";
                break;
            case "error":
                mesg.style.color = "red";
                mesg.innerHTML = "Error occured";
                break;
        }
    }
    function OnChange(txt) {
        $("#mesg")[0].innerHTML = "";
    }

This is my textbox:

 <asp:TextBox ID="txtUsername" runat="server" BorderStyle="Solid" BorderWidth="1px" BorderColor="#0099CC" BackColor="#FAFFBD" AutoCompleteType="Disabled" onkeyup = "OnChange(this)" Onblur="ShowAvailability()"></asp:TextBox>
             <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
             ControlToValidate="txtUsername" ErrorMessage="User Name is required." 
             ToolTip="User Name is required." 
             CssClass="signupvalidators" ForeColor="Red">*</asp:RequiredFieldValidator>
             <span id = "mesg"></span>

Here I’m checking it:

 <System.Web.Services.WebMethod()> _
Public Shared Function CheckUserName(ByVal userName As String) As String
   Dim returnValue As String = String.Empty
   Try
      Dim consString As String = ConfigurationManager _
            .ConnectionStrings("conString").ConnectionString
      Dim conn As New SqlConnection(consString)
      Dim cmd As New SqlCommand("spx_CheckUserAvailability", conn)
      cmd.CommandType = CommandType.StoredProcedure
      cmd.Parameters.AddWithValue("@UserName", userName.Trim())
      conn.Open()
      returnValue = cmd.ExecuteScalar().ToString()
      conn.Close()
   Catch
      returnValue = "error"
   End Try
   Return returnValue
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:26:31+00:00Added an answer on May 28, 2026 at 7:26 am

    Wrap the function

     $("#<%=txtUsername.ClientID %>").blur(function () { etc..
    

    In

    $(document).ready(function(){
    
      //.. your code here
    
    )};
    

    It could be that the DOM hasn’t loaded and the event isn’t binding the first time through. The document.ready wrapper will ensure the DOM has loaded

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : <input type=text id=myText class=input_box_hidden /> $(document).ready(function() { var nomeAzienda=$(#myText);
I have this function: $('input#auto_results').bind('blur', function(e) { $('.result').bind('click', function() { return; }); $('#results_container').hide(); });
I have this: $(window).blur(function() { setInterval(function() { $.ajax({ type: POST, url: imback.php, data: {
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have a form with some text-inputs: login, password. If user sees this form
Here's my javascript: $(.more_info).hide(); $(.checkbox.has_info, .has_info).focus(function(){ $(this).parent().next().next().show(fast); }); $(.checkbox.has_info, .has_info).blur(function(){ $(this).parent().next().next().hide(fast); }); Note, that
I have a button 'button' that activates a dropdown box 'box': $('.button').click(function() { $(this).siblings(.box).toggle();
Suppose I attach an blur function to an HTML input box like this: <input
I have the following JQuery function being attached to the blur event of n
I have this piece of code: window.addEventListener( focus , function(){ window.console.log(focus); } , false

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.