Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 19th, 2004, 08:17 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text box value

How do I get a text box to add leading zero's to any number entered. So the text box will be 9 characters max in length. If a user enter 5 numbers, I would the other 4 numbers to be leading zero's. For example, if a user entered 12345, I would like the result when the web form is submitted to look like 000012345.

Please help.

Thanks,
Tee
Reply With Quote
  #2 (permalink)  
Old October 19th, 2004, 08:49 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Tee,

Try this...

Code:
function CheckValues(pForm){
    var ok = true;
    var temp = pForm.myText.value;
    if(/^\d*$/.test(temp)){
        var padding = "000000000";
        temp = padding.substr(temp.length) + temp;
    }else{
        alert("Please enter an integer value");
        ok = false;
        temp = "";
    }
    pForm.myText.value = temp;    
    return ok;
}
...

<form id="myForm" name="myForm" onsubmit="return CheckValues(this);" >
    <input type="text" id="myText" name="myText" />    
    <input type="submit" value="Go" />
</form>
HTH,

Chris


Reply With Quote
  #3 (permalink)  
Old October 19th, 2004, 10:39 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Chris..I will give it a try.:)

Reply With Quote
  #4 (permalink)  
Old October 19th, 2004, 11:13 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, that did not work.

thanks though
Reply With Quote
  #5 (permalink)  
Old October 19th, 2004, 11:17 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Tee,

Strange - works for me in IE & Mozilla, can you post your code?

Thanks,

Chris

Reply With Quote
  #6 (permalink)  
Old October 19th, 2004, 01:02 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is just a simple form going to a SQL DB.

<form method="get" action="insert.asp" name="Form" >

        <div align="center">
        <table border="0" width="660" id="table1">
            <tr>
                <td>
                <p align="center"><br>
                <b><br>
&nbsp;</b></td>
                <td width="433">
                <p align="center">
                &nbsp;</td>
            </tr>
        </table>

        <table width="651" border="0">
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2"><b>[u]Customer Information</u></b></td>
          </tr>

          <tr>
            <td>Account #</td>
            <td><span style="font-size: 11pt"><input type="text" name="acct" size="9"></span></td>
          </tr>
          <tr>
            <td>Phone number:<br>
            <b>(including area code)</b></td>
            <td><span style="font-size: 11pt">
            <input type="text" name="phone" size="20"></span></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2">Please select the
            equipment the customer is missing (check all that apply):</td>
          </tr>
          <tr>
            <td colspan="2">
            <table border="0" width="651" id="table2">
                <tr>
                    <td width="108">
                    <span style="font-size: 11pt">
                    <input type="checkbox" name="digital" value="yes"></span>&nbsp;
                    Yes</td>
                    <td width="108">
                    <span style="font-size: 11pt">
                    <input type="checkbox" name="HDTV" value="yes"></span>&nbsp;
                    No</td>
                    <td width="108">&nbsp;</td>
                    <td width="108">&nbsp;</td>
                    <td width="108">&nbsp;</td>
                    <td width="109">&nbsp;</td>
                </tr>
            </table>
            </td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2" height="28"><p>

                <input name="Submit" type="submit" value="Submit">
                <input type="reset" name="R1" value="Reset">

              </p></td>
          </tr>
        </table>
            </div>
            <p>&nbsp;</p></td>



</form>


thanks for your help!


Reply With Quote
  #7 (permalink)  
Old October 20th, 2004, 03:25 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Tee,

Add this script to your page...
Code:
function PadIntField(pField){
    var ok = true;
    var temp = pField.value;
    alert(pField.maxLength);
    if(/^\d*$/.test(temp)){
        var padding = "";
        for(var i = 0; i < pField.maxLength; i++){
            padding += "0";
        }
        temp = padding.substr(temp.length) + temp;
    }else{
        alert("Please enter an integer value");
        ok = false;
        temp = "";
    }
    pField.value = temp;    
    return ok;
}
then add
Code:
onsubmit="return PadIntField(this.acct);"
to your form tag and
Code:
maxLength="9"
to your acct input tag.

Cheers,

Chris


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM
Rich Text Box vs Text Box snowy0 VB.NET 2002/2003 Basics 1 February 17th, 2004 02:11 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM



All times are GMT -4. The time now is 03:17 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.