Reply
Simple function with variables issue
Old 02-17-2008, 04:10 AM Simple function with variables issue
Experienced Talker

Posts: 47
Name: Bruce
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 05:43 AM.
SillyWilly is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 02-17-2008, 04:24 AM Re: Simple function with variables issue
chrishirst's Avatar
Super Moderator

Posts: 13,609
Location: Blackpool. UK
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!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-17-2008, 04:45 AM Re: Simple function with variables issue
Experienced Talker

Posts: 47
Name: Bruce
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 05:44 AM.
SillyWilly is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Simple function with variables issue
 

Thread Tools

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

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