462,893 Members | 785 Online
Need help? Post your question and get tips & solutions from a community of 462,893 IT Pros & Developers. It's quick & easy.

 P: 6 I need to add leading zeroes to an input box. For example, the user enters "2" , I need to convert to a three digit number eg."002". If the user enters "23", I need to convert to "023" If the user enters a three digit number leave it alone. Thanks for your help. Nov 20 '07 #1
9 Replies

 100+ P: 1,137 By convert do you meen convert it in your variable, or convert it when the user enters it? Thanks, Death Nov 20 '07 #2

 P: 6 By convert do you meen convert it in your variable, or convert it when the user enters it? Thanks, Death when the user enters it, Nov 20 '07 #3

 100+ P: 1,137 You would have to check the users input, and then based on that input, change the value of text. How you would do this i'm not entirely sure. I know bits and pieces of what you would need to do, but no clue on a few parts. Acoder or Gits will probably know, they should be along shortly. Thanks, Death Nov 20 '07 #4

 P: 6 You would have to check the users input, and then based on that input, change the value of text. How you would do this i'm not entirely sure. I know bits and pieces of what you would need to do, but no clue on a few parts. Acoder or Gits will probably know, they should be along shortly. Thanks, Death Thanks for your response. :-) Nov 20 '07 #5

 Expert Mod 5K+ P: 5,390 hi ... you may use something like the following example: Expand|Select|Wrap|Line Numbers function fill_value(value) {     var l = 3;     var t = [];     var v = [];       if (value.length <= l) {         t = value.split('');           var tl = l - t.length;           for (var i = 0; i < l; i++) {            if (i < tl) {                v.push('0');            } else {                for (var j = 0; j < t.length; j++) {                    v.push(t[j]);                }                break;            }         }     } else {         var re = new RegExp('^.{' + l + '}');           v = value.replace(/.+/, value.match(re)).split('');     }     return v.join(''); }   kind regards Nov 20 '07 #6

 100+ P: 428 Expand|Select|Wrap|Line Numbers Untitled Document     function padZero(who,len){     var n= who.value;     n=n.replace(/^0+/,'');         while(n.length< len) n= '0'.concat(n);     who.value= n; }   Nov 21 '07 #7

 Expert Mod 5K+ P: 5,390 heya mrhoo ... nice :) much better then mine ... was late last evening ;) kind regards Nov 21 '07 #8

 Expert Mod 15k+ P: 16,027 Acoder or Gits will probably know, they should be along shortly. ...or mrhoo, don't forget mrhoo! Nice work! :) Nov 21 '07 #9

 100+ P: 1,137 [HTML] [/HTML] All fixed lol. - Death PS - Incase you don't already know this, the code above will not work. Nov 21 '07 #10