www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] OnBlur Not firing... asp.net 2.0

  1. #1
    Join Date
    Feb 2004
    Posts
    86

    resolved [RESOLVED] OnBlur Not firing... asp.net 2.0

    When I type in a phone number... 6125559900 and then tab off it does not fire... but when I tab back to it and then tab off again. Then it fires. Have any ideas?

    VB.net 2.0 (Page_Load):
    Code:
    txtPhone1.Attributes.Add("onblur", "return doFormatPhone1(this, true);")
    ASP.net 2.0:
    Code:
    <asp:textbox id="txtPhone1" runat="server" Width="95px" TabIndex="35"></asp:textbox></TD>

    ASP.net 2.0 (Script):
    Code:
    <script language=javascript>
    
    
    function doFormatPhone1(phoneobj)
    {
          // set form field where phone format should take place
          var gotphone = document.getElementById("ctl00_middleContent_ctlDemoInfo_txtPhone1");
    
          gotphone.onblur = function()
          {
                formatPhone(this);
          }
    }
    function doFormatPhone2(phoneobj)
    {
          // set form field where phone format should take place
          var gotphone = document.getElementById("ctl00_middleContent_ctlDemoInfo_txtPhone2");
    
          gotphone.onblur = function()
          {
                formatPhone(this);
          }
    }
    function doFormatPhone3(phoneobj)
    {
          // set form field where phone format should take place
          var gotphone = document.getElementById("ctl00_middleContent_ctlDemoInfo_txtPhone3");
    
          gotphone.onblur = function()
          {
                formatPhone(this);
          }
    }
    
    /* Format phone number function */
    function formatPhone(curPhone)
    {
          curPhone.value = formatPhoneStr(curPhone.value);
    }
    
    /* Returns a formatted phone number */
    function formatPhoneStr(phoneNumber)
    {
          var tempPhone = phoneNumber.replace(/[^0-9xX]/g,"");
    
          tempPhone = tempPhone.replace(/[xX]/g,"x");
    
          var extension = "";
    
          if(tempPhone.indexOf("x") > -1)
          {
                extension = " "+tempPhone.substr(tempPhone.indexOf("x"));
    
                tempPhone = tempPhone.substr(0,tempPhone.indexOf("x"));
          }
    
          switch(tempPhone.length)
          {
              case(7):
                  //return tempPhone.text("(612)")
                  //return tempPhone.replace("(612)",/(...)(...)(....)/g,"($1) $2-$3")+extension;
                  return "(612) " + tempPhone.substr(0, 3) + "-" + tempPhone.substr(3, 4);
                case(10):
                      return tempPhone.replace(/(...)(...)(....)/g,"($1) $2-$3")+extension;
                case(11):
                      if(tempPhone.substr(0,1) == "1")
                      {
                            return tempPhone.substr(1).replace(/(...)(...)(....)/g,"($1) $2-$3")+extension;
                      }
    
                      break;
                default:
          }
    
          return phoneNumber;
    }
    
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    What does the HTML look like?
    Stephen

  3. #3
    Join Date
    Feb 2004
    Posts
    86
    Actually... I just got it figured it out.

    I was adding the onblur event in code, but then in the doFormatPhone1() function in javascript, I was attaching another event handler. I should of change onblur to formatPhone() instead of just calling that initially.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles