?
Solved

Formatting Phone numbers and SS# in DispWin

Posted on 2003-03-30
3
Medium Priority
?
226 Views
Last Modified: 2012-08-14
Hi, I am new to javascripting so any help provided will be greatly appreciated.

I am writing a credit card application and can seem to get the phone number fields or the social security field to format correctly.  The form part of my code is working correctly.  below is a portion of what I have:

var     areacode,
                    exchange,
                    phonenum,
                    phone,
                    formattedPhone;

                    areacode = phone.substrring(0,3),
                    exchange = phone.substring(3,6),
                    phonenum = phone.substring(6,9),
                    phone = form1.HomePhone.value,
                    formattedPhone ="(" + areacode + ") " + exchange + " - " + phonenum;

               function Display()

               {    
         
               DispWin = window.open("", 'NewWin', 'toolbar = no', 'status = no', 'width = 300', 'height = 200');
         
               message = "<b>Your Credit Card Application has been processed:<br><br></b>";

message += "<li><b>HOME PHONE NUMBER: </b> " + formattedPhone;
DispWin.document.write(message);
          }

Also, I am also having problems with setting up in the DispWin the calculation of income and expense ratio to provide a approve/decline statement.  Thank you.
0
Comment
Question by:mileseve1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
gator4life earned 80 total points
ID: 8236279
This area of code:

areacode = phone.substrring(0,3),
exchange = phone.substring(3,6),
phonenum = phone.substring(6,9),
phone = form1.HomePhone.value,
formattedPhone ="(" + areacode + ") " + exchange + " - " + phonenum;

Should look like this:

phone = document.forms('form1').HomePhone.value;
areacode = phone.substring(0,2);
exchange = phone.substring(3,5);
phonenum = phone.substring(6,9);
formattedPhone = '(' + areacode + ') ' + exchange + ' - ' + phonenum;

Remember that each line of JavaScript has to be separated by a semicolon (;); yours were not.  Next, the "phone" variable has to be populated with a value before you can act upon it with other methods; in your code, "phone" is populated *after* you are trying to access its value.  Lastly, this code only works if your user types in *exactly* 10 numbers; no more, no less, and no letters, special characters, etc.  Therefore, it would be wise of you to think about setting up some validation code for that phone number field before trying to format it.

For the SS#, income, and expense ratio stuff, I have no idea what you are trying to do, since you did not provide any information on these.

gator4life
(chomp, chomp)
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10150285
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: gator4life {http:#8236279}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question