Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript function for textbox 1

Status
Not open for further replies.

michealmale

Programmer
Jan 30, 2008
4
0
0
US
Hi Guys,

I am writing a program in java whcih includes some jsp pages also. In my jsp page i have a situation where a user is suppose to enter Vendor Id. This textbox is limited to 5 characters.

The user might enter 325 or 12345 or 12. If the user enter less than 5 digits i would like to append 00 to make it a 5 digiti. Meaning User ent:

325
After clicking my add button to presist the data in the database i would like to make 325 to 00325 same thing goes for 12 will be recognized as 00012.

Can someone help me on this?
 
But my problem is related to javascript function. I am trying to write a javascript function where it will automatically insert 00 to make it exact 5 digit.
 
I am trying to write a javascript function where it will automatically insert 00 to make it exact 5 digit.

Why don't you show us what you've tried so far and we can tell you what you're doing wrong.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I have a small script for that, but I would like to see how you think it could be solved..

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Well if i knew how to write the script then why would i come to the forums in the first place?

First of all not trying to bring a bad attitude but unfortunately i dont have any experience in javascript until i was assigned to use Spring Framework in j2ee(Hope you guys know what spring framework is) in my web project.

I try to stay away from javaScript as much as i can but today was the day i said that Javascript is the only solution and now i am struggling in order to write a function.

If you can provide it that's great if not then no worries my search still continue.

Thanks
 
If it was in java i could have done in 10 sec:-

Code:
public class Test {

	public static void main(String[] args) {
		
		System.out.println(String.format("%05d", 34));

	}
	
}

Have a great day
 
OK, I see.
But you know (X)HTML basics I hope? And how you call functions with the buttons?

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
By the way... Why is it so important to use JavaScript for this? Isn't it easier to accept the integer format (i.e. 38) and format the number to fixed length (00038) with server-side scripting??

1) The browser don't need the support of JavaScript.
2) You send less data to the server (not much thou).
3) You code with a language you already know..

As you said, you just mentioned a function in Java. Think about it..

- Lowet

[gray]Why can't all browsers parse pages the same way? It should be the Web designer who decides how to display the content, not the browser![/gray]
 
Well if i knew how to write the script then why would i come to the forums in the first place?

Umm... maybe to ask for help on some code that you've attempted, but couldn't get it to work. If you haven't even attempted to solve it yourself, why should anybody else attempt to do it for you?

To give you an idea, check out this thread:

thread216-1446408

Person was having trouble with his code, posted what he was having problems with, and we were able to make an informed suggestion based on his work. That was a textbook thread - kudos to the OP.

Like you said above, you are "[!]trying[/!] to write a javascript function where it will automatically insert 00 to make it exact 5 digit." If you haven't really tried to write the function, why should someone else?

If you're just completely green to javascript, you could have said that from the start and someone could have suggested sites where you could learn the language. is a good place to start.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top