Sending array values from HTML to external JS

Hey all, learning JS and trying to take this script I found that was intended to be included in the head and convert it to an external js.

It is a slideshow script, however I want to use it as an external because I have multiple pages for a portfolio in which I want to have the slideshow and have them use this script.

Problem with the script is that you need to define the values of the array in the script so I am trying to change it so I can define them in the HTML file and then send them to the external js.

external JS


var photos=new Array()

function assignphoto(x,imval){
    photos[x]=imval;
    return photos[x];
}

HTML


<script type="text/javascript" src="slideshow.js">
    //<![CDATA[
        
    assignphoto(0,"images/portfolio/amputee/amp001.jpg");
    assignphoto(1,"images/portfolio/amputee/amp002.jpg");
   

    //]]>
</script>

to me this should work because the function receives the array position and the string.

I have tried it multiple ways, assigning a separate var s in the html and doing stuff there to send it.

Is there a better way to define and or retrieve the value I want for the array positions?
I’ve seen some examples that use the document.getElementById() but I’m new and unsure how I would define the value in both the HTML and external JS.

link to orig js from dynamicdrive http://www.dynamicdrive.com/dynamicindex14/dhtmlslide.htm

THX

[quote==guinness=;2358565]Problem with the script is that you need to define the values of the array in the script so I am trying to change it so I can define them in the HTML file and then send them to the external js.
[/quote]

<script type="text/javascript" src="slideshow.js">
    //<![CDATA[
        
    assignphoto(0,"images/portfolio/amputee/amp001.jpg");
    assignphoto(1,"images/portfolio/amputee/amp002.jpg");
   

    //]]>
</script>

The script is all “compiled” as one page when the browser loads, so there isn’t a difference other than organization. If this is the code you are using, the problem is stemming from the fact that you are combining a script include with inline scripts. The above should be two separate script elements like this:

<script type="text/javascript" src="slideshow.js"></script>
<script type="text/javascript">    
//<![CDATA[
        
    assignphoto(0,"images/portfolio/amputee/amp001.jpg");
    assignphoto(1,"images/portfolio/amputee/amp002.jpg");
   

    //]]>
</script>

crap, that’s been the problem the whole time. it works now. the littlest things…

thanks a lot actionAction!

still new to the syntax and structure of this.

glad I could help! :slight_smile: