Little Goat Posted April 8, 2006 Share Posted April 8, 2006 I'm trying to get a counter to work, thanks to scott100 http://w3schools.invisionzone.com/index.ph...655entry17655 and I want to make images work with it. all I need to know is how to make php variables available to javascript. can I do this?LG Link to comment Share on other sites More sharing options...
Little Goat Posted April 8, 2006 Author Share Posted April 8, 2006 nevermind, I realized that i could just do this: <script type="text/javascript">var number="<?php echo $number;?>"</script> if I'm wrong will someone tell me?LG Link to comment Share on other sites More sharing options...
Little Goat Posted April 8, 2006 Author Share Posted April 8, 2006 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 More sharing options...
Chocolate570 Posted April 8, 2006 Share Posted April 8, 2006 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 More sharing options...
Little Goat Posted April 8, 2006 Author Share Posted April 8, 2006 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 More sharing options...
Chocolate570 Posted April 9, 2006 Share Posted April 9, 2006 No problem, good luck with it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now