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-20-2006, 12:21 PM lops with javascript
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Hi

Ive got a piece of js code which currently i am repeating as i dont know javascript and cant make a loop. Please help me arrange this code so it loops. This is the code as is:


HTML Code:
<script>
if(document.images) 
{ col = new Array() 
for(i=0;i<10;i++) 
{ col[i] = new Image() 
col[i].src = "http://www.webmaster-talk.com/images/col" + i + ".gif" } } 

function glassauto1() 
{if(document.images){document.colswitch1.src="http://www.webmaster-talk.com/images/col"+document.doorglass.door1glass.selectedIndex+".gif"}}
window.onerror=null; 

function glassauto2() 
{if(document.images){document.colswitch2.src="http://www.webmaster-talk.com/images/col"+document.doorglass.door2glass.selectedIndex+".gif"}}
window.onerror=null; 
</script>
and this is along the lines of what i want

HTML Code:
<script>
if(document.images) 
{ col = new Array() 
for(i=0;i<10;i++) 
{ col[i] = new Image() 
col[i].src = "http://www.webmaster-talk.com/images/col" + i + ".gif" } } 

var numdoor = doorform.numdoor.value; // for example 2
for(b=1; b< numdoor ;b++)
{
function glassauto[b]() 
{if(document.images){document.colswitch[b].src="http://www.webmaster-talk.com/images/col"+document.doorglass.door[b]glass.selectedIndex+".gif"}}
window.onerror=null; 
}

</script>
Id be most greatly if you can help me sort this simple script.

Last edited by hiptobesquare; 02-20-2006 at 12:26 PM..
hiptobesquare is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-21-2006, 11:15 AM Re: lops with javascript
ermau's Avatar
Experienced Talker

Latest Blog Post:
Chopper pwnage
Posts: 47
Name: Eric
Location: Florida
Trades: 0
Code:
if (document.images)
{
    var col = new Array();
    for (var i = 0; i < 10; i ++)
    {
         col[i] = new Image();
         col[i].src = "http://www.webmaster-talk.com/images/col" + i + ".gif"
    }
}

var numDoor = doorform.numdoor.value;
for (var i = 0; i < numDoor; i++)
{
    if (document.images)
    {
        document.colswitch[b].src="http://www.webmaster-talk.com/images/col"+document.doorglass.door[i]glass.selectedIndex+".gif"
        window.onerror = null;
    }
}
Only problem is where you have a [i] inside the url. I wasn't sure how it was supposed to go, but that is most certainly invalid syntax.
__________________
PHP / mySQL Developer
ermau is offline
Reply With Quote
View Public Profile
 
Old 02-21-2006, 03:20 PM Re: lops with javascript
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Yeah thanks for looking. I have tried various ".i." and [i] but nothing seems to work. il just stick with 5 repetitions of the same code i think.
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Old 02-23-2006, 06:03 PM Re: lops with javascript
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
if you can post the full HTML, or working HTML, I could help... I just need a better idea of what you are trying to do... Looks like you want to change an image when a drop down is selected. Why not just do:

Code:
function swap(dropdownValue, imgTarget) {
     iTarget = document.getElementById(imgTarget);
     imgTarget.src = "http://www.webmaster-talk.com/images/col" + dropdownValue + ".gif";
}
and call it with
Code:
onchange="swap(this.selectedIndex,'theImage');"
in the select box?
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 02-28-2006, 09:30 AM Re: lops with javascript
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Hi funkdaddu

thanks for looking at this thread, ive given up on this particular problem now and just used 5 repeated sections of code.

I do have a very similar problem will il post up shortly
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Old 03-05-2006, 01:53 PM Re: lops with javascript
Super Talker

Posts: 144
Trades: 0
i believe you were looking for something along the lines of:

document.images["imageName"+ x].src = my_img.src;
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Reply     « Reply to lops with javascript
 

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