Jump to content

can javascript...


Little Goat
 Share

Recommended Posts

OK, another question, how do I make a number a specific length by adding zero's to the left end and then seperate the digits of the number?for example, say I have this: Number=182 First I want the javascript lengthen the number to, say 7 digits,resulting in: Number=0000182.then I want to seperate the individual digits so that an array holds them: num[1]=0, num[2]=0,...num[5]=1, num[6]=8, num[7]=2.can anyone help me plz?LG

Link to comment
Share on other sites

Please don't triple post. Edit your original post. Thanks.For your first question, that is correct--just use the echo statement on a php page.For the second question, use this.

<script type="text/javascript">firNum="0005947" //put number herenum=[];for(i=0;i<=firNum.length;i++) {num[i]=firNum.charAt(i-1)}alert(num[4]) //do whatever you would like with the array num[].</script>

Link to comment
Share on other sites

thanx, Choco!I'm using it for a counter.the counter in the post I linked to.I wanted to use images for the counter, and thanx to you now I can!My code (that works):

<html><head><title>number</title></head><body><script type="text/javascript">var number='182';len=number.length;zeros=7;zeros=zeros-len;var zero="";for (i=0;i<zeros;i++){zero+="0";}finNum=zero+number;num=[];for(i=1;i<=finNum.length;i++) {num[i]=finNum.charAt(i-1);document.write("<img src='"+num[i]+".gif' alt='"+num[i]+"'/>");}</script></body></html>

I'm oing to replace the number with a <?php include?> statement to display my counter.thanx again,LG

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...