473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Help! Need to add lead zeros to a textbox input

I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
6 1400
Hi sorry I add my question hehe I cant write new queston it say the session is expired do you have any idea?

"TN Bella" wrote:
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
My suggestion is to check the length of string and use a for-loop to add
appropiate amount of zeros the it.

You may do it in server-side or client-side, depends on when you want to add
the zeros and which one you feel more handy. Though I'll prefer to do it
client-side as the user will know you've automatically added the leading
zeros for it.

Regards,
Lau Lei Cheong

"TN Bella" <ti********@nav-international.com> ???
news:eM**************@TK2MSFTNGP09.phx.gbl ???...
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3
If txtRefNum.Text.Length < 9 Then
txtRefNum.Text = txtRefNum.Text.PadLeft(9, "0")
End If
I got this to work but I need to add more values (14 more) to the
code...txtRefNum - txtRefNum14

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
In javascript you can supply the textcontrol's name as parameter and use
eval() or document.getElementById() to do so. I don't know much in vbscript
but you may try the Eval() function too.

Dim myctrl = Eval("txtRefNum")

If you can use it, you can supply a parameter to the function.

Good luck. :)

"TN Bella" <ti********@nav-international.com> ???
news:Oi*************@TK2MSFTNGP09.phx.gbl ???...
If txtRefNum.Text.Length < 9 Then
txtRefNum.Text = txtRefNum.Text.PadLeft(9, "0")
End If
I got this to work but I need to add more values (14 more) to the
code...txtRefNum - txtRefNum14

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
use this:

txtRefNum.Text = Format(Val(txtRefNum.Text), "0########")

--
Hope this helps,
Zeeshan Mustafa, MCSD
"Lau Lei Cheong" <le****@yehoo.com.hk> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl...
In javascript you can supply the textcontrol's name as parameter and use
eval() or document.getElementById() to do so. I don't know much in vbscript but you may try the Eval() function too.

Dim myctrl = Eval("txtRefNum")

If you can use it, you can supply a parameter to the function.

Good luck. :)

"TN Bella" <ti********@nav-international.com> ???
news:Oi*************@TK2MSFTNGP09.phx.gbl ???...
If txtRefNum.Text.Length < 9 Then
txtRefNum.Text = txtRefNum.Text.PadLeft(9, "0")
End If
I got this to work but I need to add more values (14 more) to the
code...txtRefNum - txtRefNum14

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



Nov 18 '05 #6
If u want to use from javascript u can use this function on blur of textbox
/*Events Fires on blur of TextBox*/
function fnChange()
{
var obj;
obj=document.getElementById('txtName'); //get the context of txtName element
if (obj!=null)
{
if (Number(obj.value.length)<9)
{
Val=obj.value.toString(); //converts to string
Val= '000000000' + Val ; //append 9 0's to the string
obj.value=Val.substr(obj.value.length,Val.length); //gets the substring of Val.
//like right function right(String,startindex)
}
}
}
if u want this should happen on post back u can use this
txtRefNum.Text = Format(Val(txtRefNum.Text), "0########")

"TN Bella" wrote:
I have a simple text box called txtrefnum, if the user enters a number
length less than 9 characters long than I need to have lead zeros
added to it. Does anyone know how to do this? I couldn't find anything
online on the subject...

<asp:TextBox id="txtRefNum" runat="server"></asp:TextBox>

I thought I could use a validator for the process and make the user
add the zeros, but of course that is a big no-no! Please help!!

Thanks!


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
6
by: priyajohal | last post by:
#include<fstream.h> #include<process.h> #include<stdlib.h> #include<conio.h> #include<string.h> #include<dos.h> #include<ctype.h> #include<stdio.h> void setup() void help();
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.