# Pass through parameter to JavaScript

**URL:** <https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823>\
**Category:** How-to Discussions\
**Created:** [September 2, 2015, 11:20am UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823 "2015-09-02T11:20:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Rob](https://forums.fusetools.com/u/Rob)\
**Post date:** [September 2, 2015, 11:20am UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/1 "2015-09-02T11:20:07Z")

</div>

Hi,

I have a StackPanel layout with a loop of Card elements, and I’ve got a click event attached to them, how do I go around passing through a parameter to my JS click handler?

```auto
        <Clicked Handler="{cardClicked}" />

```

function cardClicked(this) { debug\_log(“test”); debug\_log(this.data); }

```auto
    It returns an object, but how do: onClick="cardClicked(i)";?

```

Another thing I was wondering is how to get the current position of the Each loop?

Cheers

---

<div class="post-metadata">

**Author:** ![Terje\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/terje_pedersen/32/243_2.png) [@Terje\_Pedersen](https://forums.fusetools.com/u/Terje_Pedersen)\
**Post date:** [September 2, 2015, 9:27pm UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/2 "2015-09-02T21:27:14Z")

</div>

I don’t know if its possible to add parameters since I have just started with Fuse today but you could use something like:

```auto
function cardClicked(sender) {
   var index = cards.indexOf(sender.data);
}

```

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [September 3, 2015, 2:46am UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/3 "2015-09-03T02:46:27Z")

</div>

Rob: All events have a `.data` parameter on the argument which contains the data context for the object the event relates to, e.g.

```auto
function cardClicked(e)
{
    e.data // <-- this is the data for the card
}

```

---

<div class="post-metadata">

**Author:** ![andreseku](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@andreseku](https://forums.fusetools.com/u/andreseku)\
**Post date:** [September 5, 2015, 9:46pm UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/4 "2015-09-05T21:46:35Z")

</div>

What would be in .data? And how could I access it?

```auto
<Image Url="{imageUrl}" Clicked="{pressItem}"/>

```

I have a List of NewsItem (same as in the SocialMediaMock Sample) - and I want to switch to a “Detail Page” of the clicked item… so I would need to get the Information of which Item got clicked, so that I could load a new page with the details of this item.

---

<div class="post-metadata">

**Author:** ![Terje\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/terje_pedersen/32/243_2.png) [@Terje\_Pedersen](https://forums.fusetools.com/u/Terje_Pedersen)\
**Post date:** [September 6, 2015, 8:46am UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/5 "2015-09-06T08:46:05Z")

</div>

.data contains your NewsItem. You can use Utilites \> Build & Debug log to see what it contains like in this example:

```auto
function pressItem(e) {
    console.log(JSON.stringify(e));
}

module.exports = {
    pressItem: pressItem
}

```

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [September 6, 2015, 3:15pm UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/6 "2015-09-06T15:15:41Z")

</div>

`.data` on an event contains the data context for the object on which the event originated.

For example:

```auto
<App>
    <JavaScript>
        module.exports = {
            items: ["B", "C", "D"],

            foo: function (e) { ... / use e.data / }
        }
    </JavaScript>

    <StackPanel>
      <Button Text="A" Clicked="{foo}" />
      <Each Items="{items}">
          <Button Text="{}" Clicked="{foo}" />
      </Each>
    </StackPanel>
</App>

```

In this case, if you click the `A`-button, `e.data` will be the entire `module.exports` object.

If you click `B`, `C` or `D`, `e.data` will be the strings `"A"`, `"B"` and `"C"` respectively.

---

<div class="post-metadata">

**Author:** ![Terje\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/terje_pedersen/32/243_2.png) [@Terje\_Pedersen](https://forums.fusetools.com/u/Terje_Pedersen)\
**Post date:** [September 6, 2015, 9:15pm UTC](https://forums.fusetools.com/t/pass-through-parameter-to-javascript/6823/7 "2015-09-06T21:15:39Z")

</div>

“B”, “C” and “D” 😉
