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):
ASP.net 2.0:Code:txtPhone1.Attributes.Add("onblur", "return doFormatPhone1(this, true);")
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>


Reply With Quote
Bookmarks