/    Sign up×
Community /Pin to ProfileBookmark

help regarding the values…

hi…

i have a input type field as follow:

Voucher No.:-<input type=”text” name=”vouno” size=”4″>

i want to do that..when i enter value 1 in this field..it takes as 0001..
when i enter 10, it will take value as a 0010, when i enter 100..it will take values as 0100.and when i enter values 1000…and more than that it will take same as it is…

help me….

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@scragarMar 15.2005 — [code=php]<script type="text/javascript">
<!--
function foo(){
vouno.value = vouno.value.replace(/[^0-9]/g, "");
var i = vouno.value + "";
if(i.length == 0){
i = "0000";
}else
if(i.length == 1){
i = "000"+i;
}else
if(i.length == 2){
i = "00"+i;
}else
if(i.length == 3){
i = "0"+i;
};
vouno.value = i;
};
//-->
</script>
Voucher No.:-<input type="text" name="vouno" size="4" onblur="foo();">[/code]
×

Success!

Help @abhit_kumar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...