Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello can some guru be so kind to convert this to Javascript please 6

Status
Not open for further replies.
Jul 13, 2001
180
US
<script language=vbs>
dim myPics
sub setPics()
myPics = array (&quot;Pic1.jpg&quot;,&quot;Pic2.jpg&quot;,&quot;Pic3.jpg&quot;,&quot;Pic4.jpg&quot;,&quot;Pic5.jpg&quot;)
outStr = &quot;&quot;
randomize()
do while uBound(myPics) > 0
ranNum = fix(Rnd() * (uBound(myPics)+1))
outStr = outStr & &quot;<img src='&quot; & myPics(ranNum) & &quot;' title='&quot; & myPics(ranNum) & &quot;'>&quot;
resetArray(ranNum)
loop
'add remaining picture
outStr = outStr & &quot;<img src='&quot; & myPics(0) & &quot;' title='&quot; & myPics(0) & &quot;'>&quot;
document.getElementById(&quot;picPlace&quot;).innerHTML = outStr
end sub

sub resetArray(usedVal)
dim tempArr(), arrCount
arrCount = 0
for x = 0 to uBound(myPics)
if x <> usedVal then
redim preserve tempArr(arrCount)
tempArr(arrCount) = myPics(x)
arrCount = arrCount + 1
end if
next
redim myPics(uBound(tempArr))
for x = 0 to uBound(tempArr)
myPics(x) = tempArr(x)
next
end sub
</script>
<body onLoad=&quot;setPics()&quot;>
<div id=&quot;picPlace&quot;></div>


Thanks in advance!
 
Hello, thank you, but my code doesn't work correctly.( the part with the urls that I added in). If you run it , the urls don't always match the appropriate image. What am I doing wrong? I spent hours trying to figure out why. The code looks correct I think.

Your help is greatly appreciated.

Thanks in advance.
 
Technically it is impossible for that to get messed up.

Since you are using the same index of both arrays with the
[ranNum] . Do the array's index's you have setup
correspond to thier rep. pic??

myPics[0] = &quot;Pic1.jpg&quot;
url[0] = &quot;
With your original array generation this has to be
a matched set then when the ranNum is picked it has
to pick the pair...

To help with troubleshooting here's a tip

temporarily add this:

myPics.splice(ranNum, 1); alert(arOut);

Then you will see your script's output.


2b||!2b
 
Got it,

myPics.splice(ranNum, 1);

This line removes a myPics array index..
According to your last post you are not making
that adjustment to your url array
add the red code

myPics.splice(ranNum, 1); url.splice(ranNum, 1);

Make Sensssse...


2b||!2b
 
Brilliant!!!

And thank you!! : ) :) :) :) :)

What did that do to make it work correctly if I may ask?
 
everytime an array index was selected
it must be discarded so that it can't be selected
again.

So before you added that line, your url array no longer
was a match to your pic Array.

Your pic array was being reduced but not your
url array so you had mismatches.

2b||!2b
 
Did the rollovers work?

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
mwolf00 : Yes they did! BIG TIME!
My sincere apolgies , I got a littled mixed up and almost forgot to thank you for the rolover implementations.

mwolf00, thank you so much. I was able to accomplish my task in part to your great help.

THANK YOU so much!!!

Cheers,

Manny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top