Members Login
Username 
 
Password 
    Remember Me  
Post Info TOPIC: How to format phone numbers for Dynamic Numbers


Member

Status: Offline
Posts: 7
Date: Aug 19, 2010
How to format phone numbers for Dynamic Numbers
Permalink   
 


If you don't like the standard format used in Dynamic Numbers (xxx) xxx-xxxx you can change this with just a little bit of Javascript.

The first step is setting the _ibp_formatting variable to false in the Javascript that goes in the <head> of the page. This causes the number to be returned as an unformatted string of digits.

<script type="text/JavaScript">
var _ibp_public_key = "1234567890a";
var _ibp_formatting = false;
var _ibp_keyword_set = 1234;
</script>

Next insert the phone number as you normally would but put it inside an element that's hidden so it doesn't get displayed. When this script is included it sets a Javascript variable called _ibp_phone_number that is set to the unformatted phone number.

<div style="display:none;">
<script type="text/JavaScript" src="https://secure.ifbyphone.com/js/keyword_replacement.js"></script>
</div>

Now that we have the number in a variable we can use Javascript to break it up and format it how we like:

<script>
/* Break apart the _ibp_phone_number variable
and insert whatever characters you want */

var new_number = _ibp_phone_number.substr(0,3) + "-" + _ibp_phone_number.substr(3,3) + "-" + _ibp_phone_number.substr(6);

/* This will now write xxx-xxx-xxxx instead of (xxx) xxx-xxxx */

document.write(new_number);
</script>


Attached is an HTML file with a full example.

Dan


Attachments
__________________


Newbie

Status: Offline
Posts: 1
Date: Nov 22, 2012
Permalink   
 

Actually it would rather be the following now:
var new_number = _ibp_phone_number.substr(1,3) + "-" + _ibp_phone_number.substr(6,3) + "-" + _ibp_phone_number.substr(10);

__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.

Post to Digg Post to Del.icio.us


Create your own FREE Forum
Report Abuse
Powered by ActiveBoard