/    Sign up×
Community /Pin to ProfileBookmark

for loop only looping once?

Hi,

I have a for loop that is to look through all fields entered into a form and remove the leading zeros. It works, but only loops through once. Is there some kind of thing that once I return the leadingZero function as true the loop break or something? Any help is appreciated! thanks! This function looks like this:

function zeroStrip(input){
for(i = 0, leadingZeros = 0; i < input.length; i++)
if(input.charAt(i) == “0”)leadingZeros++;
// once something other than 0 is found…stop the loop

// remove leading zeros
input = input.substr(leadingZeros);
return input

}//end of zeroStrip function

And I call it like this:

for(i=0; i<document.FrontPage_Form2.elements.length; i++){
input = document.FrontPage_Form2.elements[i].value + “”
if(input.charAt(0) == “0”){

document.FrontPage_Form2.elements[i].value = zeroStrip(input)

input = “”

}//end of if

}//end of for

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonApr 06.2004 — How's this:

<i>
</i>
var str=document.FrontPage_Form2.elements[i].value;

while(str.charAt(0)=="0" &amp;&amp; str.length&gt;0){
str=str.substring(1,str.length);
}

document.FrontPage_Form2.elements[i].value=str;

×

Success!

Help @haunsolo 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 5.1,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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