Formatting Phone numbers and SS# in DispWin

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.
mileseve1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gator4lifeCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaysolomonCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.