Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 02-22-2008, 09:18 PM not using varible?
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
hiya

i have a bit of code that works well, goes though 8 images fine.. named 1.jpg through to 8.jpg

.................................................. .......
<script type="text/javascript">
<!--
function move(depth) {
if (depth < 8) {
depth++;
document.getElementById("move").src = depth + ".jpg";
}
setTimeout("move("+depth+");",30);
}
//-->
</script>
.................................................. ......
<a href="#" onclick="move(0)">SPIN</a>
.................................................. ......

however

if i change it to this
.................................................. .....
<script type="text/javascript">
<!--
function move(depth,stop) {
if (depth < stop) {
depth++;
document.getElementById("move").src = depth + ".jpg";
}
setTimeout("move("+depth+");",30);
}
//-->
</script>
.................................................. .......
<a href="#" onclick="move(0,6)">SPIN</a>
.................................................. .......
by adding a second variable in "stop" it stops the script completely.

normall as the first example it would show images from 1 to 8

but with the stop in it should show from 1 to 6,, but its not working.

i am new to javascript btw

can you see whats wrong?

thanks

shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!

Last edited by Sharon_leic; 02-22-2008 at 09:20 PM..
Sharon_leic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-23-2008, 12:35 AM Re: not using varible?
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I can't tell from looking at the code. Is this on a page somewhere, reachable by the outside world? I could take the code, and then copy and rename a bunch of images ... but I'm lazy.

If you're using Firefox, try using Firebug, and setting a breakpoint in your move function. This will let you run the script line by line and see what's going on ... you can also hover the mouse over your variables and see what's inside them.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-23-2008, 06:02 AM Re: not using varible?
Skilled Talker

Posts: 52
Name: Bruce
Trades: 0
The reason your second code is not working is because you're not passing it two parameters when you call the function with the setTimeout.

So if you change the setTimeout part to: setTimeout("move("+depth+","+stop+");",30); it will work. Also if you have the id the same name as the name of the function it wont work in Firefox for some reason, so you'll have to make sure the id value of the img tag is different from the name of the function you're calling.

You're doing very well for being new to javascript; you'll be a pro in no time.
I'm still new myself, but I'm learning it pretty fast.

Oh btw, about firebug, it causes insane memory leaks. My ram usage went up 300mb in like 15 clicks, PF usage went up 1gb. After hours of trying to figure out why my javascript code was causing memory leaks in FireFox I finally decided to see if it was any of the firefox addons causing the problem, and sure enough after I uninstalled Firebug I had no more memory leaks.

Hopefully FireBugs memory leak problems are fixed soon because it's a great tool.

Last edited by SillyWilly; 02-23-2008 at 06:31 AM..
SillyWilly is offline
Reply With Quote
View Public Profile
 
Old 02-25-2008, 01:52 AM Re: not using varible?
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Thanks SillyWilly that solved it and it now works good!
Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-25-2008, 08:00 PM Re: not using varible?
Skilled Talker

Posts: 52
Name: Bruce
Trades: 0
You bet!

If you ever have any trouble again, or questions then don't spend all day trying to figure them out, just ask in here. Although it is good to spend some time trying to figure them out on your own so that you'll get better at trouble shooting and finding problems in code.

I've become pretty good at finding errors in code since I was coding in a blurry monitor up until a few days ago, which caused me to not see typos very well.
SillyWilly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to not using varible?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15459 seconds with 12 queries