Javascript loop

I'm trying to preload a variable number of images. I can do most of what I want in asp but I'm not good with js.  I'd like to use only js in the load command but will consider using both vbscript and js. The snippet below is what i want but it's not rendering.

****************CODE**************

'Determine the number of images
picnumof = ((Recordset1.Fields.Item("Pictures - Number of").Value) -1)
'DEBUG TO BE REMOVED
'response.write picnumof


<%
for i=1 to picnumof
imageload = imageload + "'http://vxxxxxxxxx.maximumasp.com/ress/img/40047429_0" & i &".jpg', "
next
%>

<body onLoad="MM_preloadImages('<%=imageload%>')">
webdorkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

weddellCommented:
Using a mix of client-side javascript and server-side vbScript might be easier.


<%
'Determine the number of images
picnumof = ((Recordset1.Fields.Item("Pictures - Number of").Value) -1)
'DEBUG TO BE REMOVED
'response.write picnumof
%>

<script language="JavaScript"><!--

    for(var i=0; i < <%=picnumof%>; i++) {
           imageLoad = imageLoad + '/ress/img/40047429_0' + i + '.jpg';
    }

//--></script>

<body onload="MM_preloadImages(imageLoad)">
0
pratap_rCommented:
nu uh.. it wont work webdell, because of 2 reasons, first is you are not seperating the image files with a delimiter so you get a parameter like

/ress/img/40047429_00.jpg/ress/img/40047429_01.jpg/ress/img/40047429_02.jpg and so on

the second being MM_preloadimages (assuming the author is using the one generated by macromedia suite of apps) takes an array of parameters and not as a single string of concatenated values..

Now for the solution. webdork, your code doesn't work because of a two mistakes. First, If you notice the preparation of parameters that you are doing, you are appending a , at the end of each file. This , will be present at the last file also. Meaning, your java function call will look like

MM_preloadImages('/ress/img/40047429_01.jpg','/ress/img/40047429_02.jpg',);

this is what is creating the problem for you. so you need to strip of the last , and a space after that

do this by using
if picnumof > 0 then imageload=Left(imageload, Len(imageload) - 2)

that will strip off your final , and a space

The second mistake being,
<body onLoad="MM_preloadImages('<%=imageload%>')">

notice that you are using '<% for a javascript call so your actual rendering will look like

MM_preloadImages(''image1.jpg','image2.jpg'')
that's not a double quote but rather two ', that is the problem. just do away with the single quote.. your line should be

<body onLoad="MM_preloadImages(<%=imageload%>)">

your modified code ...

****************CODE**************

'Determine the number of images
picnumof = ((Recordset1.Fields.Item("Pictures - Number of").Value) -1)
'DEBUG TO BE REMOVED
'response.write picnumof


<%
for i=1 to picnumof
imageload = imageload + "'http://vxxxxxxxxx.maximumasp.com/ress/img/40047429_0" & i &".jpg', "
next
if picnumof > 0 then imageload=Left(imageload, Len(imageload) - 2)
%>

<body onLoad="MM_preloadImages(<%=imageload%>)">

Have Fun!
Pratap
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
webdorkAuthor Commented:
Hi Thanks all for your contribution. I'm out of town for Tgiving and away from the PC ball and chain. Back to work on Mon and will test latest suggestions and respond then. (No time for good grammer).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.