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
Simple function with variables issue
Old 02-17-2008, 05:10 AM Simple function with variables issue
Skilled Talker

Posts: 52
Name: Bruce
Trades: 0
I don't know why this isn't working. I just can't figure it out. Hopefully somebody can help me.

Basically I'm trying to change the source of 48 images onclick so I have to use variables in the getElementById, but I can't get it to work with variables.

Code:
<script type="text/javascript">

var galnum=02
var i=0

function picschange()
{
i+=1;
window.document.getElementById('imgid'+i).src='Pics/Gallery'+galnum+'/Picture'+i+'.jpg';
if (i < 2) {picschange()}
}

</script>
Code:
<img id="imgid1" src="Pics/Gallery01/Picture1.jpg">
<img id="imgid2" src="Pics/Gallery01/Picture1.jpg">

<a onclick="picschange()">CLICK</a>

Last edited by SillyWilly; 02-17-2008 at 06:43 AM..
SillyWilly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-17-2008, 05:24 AM Re: Simple function with variables issue
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
and the error you are getting is?

do we get a url to see what is not happening and of course could get the required images should the need to actually test it arise?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-17-2008, 05:45 AM Re: Simple function with variables issue
Skilled Talker

Posts: 52
Name: Bruce
Trades: 0
Ok I found the error.

I decided to document.write the variables to see what would show up and I noticed that the galnum variable was 2 and not 02 you can't have an integer 0 in front or it'll just ignore it.

So I have the problem fixed; I'll just have to change the different galnum variables to strings.

Since I figured out the problem I can now use my for loop for this instead which is faster.

Last edited by SillyWilly; 02-17-2008 at 06:44 AM..
SillyWilly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Simple function with variables issue
 

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.42687 seconds with 12 queries