Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Format phone number in dynamic text?

    On an ASP Details page, I have dynamic text with a company's address, phone and fax numbers. I want the phone and fax numbers to be formatted like (###) ###-#### on the screen. They are entered in MS Access in 10-digits only.

    I am using DWMX 2004 and am not a programmer or coder by any means. I create my recordsets in DWMX in simple mode, so if you can help me, please be specific. My field names are MbrMainPhone and MbrFax if that helps.

    Thanks!

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Something like this?

    Code:
    <script type="text/javascript">
    function formatPhone(str)
    {
    	var npa=str.substring(0,3);
    	var nxx=str.substring(3,6);
    	var line=str.substring(6,10);
    	var formatted="("+npa+") "+nxx+"-"+line;
    	return formatted;
    }
    var num=formatPhone('9165551212');
    alert(num);
    </script>
    Just pass the number to the function as I did above.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Basscyst, thanks for the response. I tried entering that into my code and it "sort-of" works but not quite what I was looking for. What happens is when I click on a company name to open up the details page (that has address, phone numbers, e-mail address, etc.), it comes up with a small pop-up window that formats the phone number, then you have to click OK, then it brings up my details page with the phone number as normal (5554443333).

    Any suggestions?

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basscyst example is merely that... An example...
    The alert was added for the sole purpose of demonstrating the code....

    You need to take the code and work it into your application (removing the offending demonstrative alert) and since you have not provided any code there is not much more that anyone can do other than providing an example as Basscyst has done....

    .....Willy

  • #5
    New to the CF scene
    Join Date
    Dec 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    Willy, maybe this will help. I created a blankpage with the "bare bones" of what I will have on the page (company name & phone number):

    <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    <!--#include virtual="/Connections/datasource.asp" -->
    <%
    var rsCoDetail = Server.CreateObject("ADODB.Recordset");
    rsCoDetail.ActiveConnection = MM_datasource_STRING;
    rsCoDetail.Source = "SELECT MbrCompany, MbrMainPhone FROM w_allcompanies";
    rsCoDetail.CursorType = 0;
    rsCoDetail.CursorLocation = 2;
    rsCoDetail.LockType = 1;
    rsCoDetail.Open();
    var rsCoDetail_numRows = 0;
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>

    <body>
    <%=(rsCoDetail.Fields.Item("MbrCompany").Value)%>
    <br>
    <%=(rsCoDetail.Fields.Item("MbrMainPhone").Value)%> (this is the line that I want to show up as formatted like (555) 444-3333)
    </body>
    </html>
    <%
    rsCoDetail.Close();
    %>

  • #6
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Don't work with asp too much but I think this might work, since you are using JS anyhow.

    Code:
    <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
    <!--#include virtual="/Connections/datasource.asp" -->
    <%
    var rsCoDetail = Server.CreateObject("ADODB.Recordset");
    rsCoDetail.ActiveConnection = MM_datasource_STRING;
    rsCoDetail.Source = "SELECT MbrCompany, MbrMainPhone FROM w_allcompanies";
    rsCoDetail.CursorType = 0;
    rsCoDetail.CursorLocation = 2;
    rsCoDetail.LockType = 1;
    rsCoDetail.Open();
    var rsCoDetail_numRows = 0;
    
    function formatPhone(str)
    {
    	var npa=str.substring(0,3);
    	var nxx=str.substring(3,6);
    	var line=str.substring(6,10);
    	var formatted="("+npa+") "+nxx+"-"+line;
    	return formatted;
    }
    var num=formatPhone(rsCoDetail.Fields.Item("MbrMainPhone").Value);
    
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <body>
    <%=(rsCoDetail.Fields.Item("MbrCompany").Value)%>
    <br>
    <%=(num)%>
    </body>
    </html>
    <%
    rsCoDetail.Close();
    %>
    Helping to build a bigger box. - Adam Matthews

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    function formatPhoneNumber(num)
      if (num == "" || num == null) {
        return "";
      }
      else {
        num = "" + num;
        var numLen = num.length;
        if (numLen == 10)
          return "(" + num.substr(0, 3) + ") " + num.substr(3, 3) + "-" + num.substr(6, 4);
        else if (numLen == 7) 
          return num.substr(0, 3) + "-" + num.substr(3, 4);
        else 
          return num;    
      }
    }

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I like using regular expressions....
    However, this example answers Connie's question as asked to format a 10 digit number and if there is a chance that 7 digit numbers will also be used some changes will need to be made...
    (call the function onload and pass the form name and input name as an arguement thru the function)

    Code:
    <script type="text/javascript">
     <!--//
      function formatPhoneNumber(input){
        if((/^(\d{3})(\d{3})(\d{4})$/).test(input.value)){
          input.value = '('+RegExp.$1+') '+RegExp.$2+'-'+RegExp.$3;
        } else{ input.value = input.value }
      }
     //-->
    </script>
    </head>
    
    <body onload="formatPhoneNumber(document.forms[0].MbrMainPhone)">
    <form>
    <input name="MbrMainPhone" value="5554443333">
    </form>
    ....Willy

  • #9
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Hey,

    Two guys that posted after me, that have done more learnin' than me, did I do that asp edit right? Just curious.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #10
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I couldn't tell you....
    I don't know a dang thing about ASP...

    Well other than an asp is also known as a snake...
    And snakes are also known as vipers...
    And Vipers are one heck of a car...

    .....Willy

  • #11
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I wonder which one they will use this one, or this one


  •  

    Posting Permissions

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