Solved

Posted on 2007-11-20
Medium Priority
975 Views
For example, the user enters "2" , I need to convert to a three digit number eg."002".
If the user enters a three digit number leave it alone.

0
Question by:marcelo27
[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
• 4

LVL 21

Assisted Solution

nizsmo earned 1500 total points
ID: 20322895
\$num = "2";

hope this helps.
0

LVL 21

Assisted Solution

nizsmo earned 1500 total points
ID: 20322906
sorry i didn't see you wanted a javascript solution, please ignore my previous post.
0

LVL 21

Accepted Solution

nizsmo earned 1500 total points
ID: 20322947
however this should help:

<script ....>
var num = "2";
var zero = "0";
if(num.length==1)
{
result = zero + zero + num;
}
else if(num.length==2)
{
result = zero + num;
}
</script>
0

Author Comment

ID: 20323147
Im not sure why var num = "2"?
The user can enter any numerical value. If the user enters a one or double digit number zeroes need to be added. The maximum length of string is 3.
0

LVL 21

Expert Comment

ID: 20323310
marcelo27:

i was giving an example and num is what you have to assign, my primary objective is to let you know that my function works :) if i didn't put the num there and an example value, you wouldn't be able to see the working code and it would be harder to understand.

hope that explains why i put "2" as num, you can put and assign any number from anywhere to the num variable.
0

## Featured Post

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
Course of the Month10 days, 17 hours left to enroll