Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Formatting Phone numbers and SS# in DispWin

Posted on 2003-03-30
3
Medium Priority
?
235 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
2 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

580 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