# Sending array values from HTML to external JS

**URL:** <https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947>\
**Category:** web dev\
**Created:** [July 14, 2008, 9:10pm UTC](https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947 "2008-07-14T21:10:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guinness](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@guinness](https://forum.kirupa.com/u/guinness)\
**Post date:** [July 14, 2008, 9:10pm UTC](https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947/1 "2008-07-14T21:10:05Z")

</div>

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

```auto

var photos=new Array()

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

```

HTML

```auto

<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](http://www.dynamicdrive.com/dynamicindex14/dhtmlslide.htm)

THX

---

<div class="post-metadata">

**Author:** ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)\
**Post date:** [July 14, 2008, 9:19pm UTC](https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947/2 "2008-07-14T21:19:47Z")

</div>

[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]

```auto
<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:

```auto
<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>

```

---

<div class="post-metadata">

**Author:** ![guinness](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@guinness](https://forum.kirupa.com/u/guinness)\
**Post date:** [July 14, 2008, 9:48pm UTC](https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947/3 "2008-07-14T21:48:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![actionAction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/actionaction/32/3987_2.png) [@actionAction](https://forum.kirupa.com/u/actionAction)\
**Post date:** [July 15, 2008, 1:45am UTC](https://forum.kirupa.com/t/sending-array-values-from-html-to-external-js/265947/4 "2008-07-15T01:45:22Z")

</div>

glad I could help! 🙂
