# Slider button is pressed or released...

**URL:** <https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933>\
**Category:** How-to Discussions\
**Created:** [March 7, 2016, 7:52am UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933 "2016-03-07T07:52:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Onur\_Baran](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/onur_baran/32/127_2.png) [@Onur\_Baran](https://forums.fusetools.com/u/Onur_Baran)\
**Post date:** [March 7, 2016, 7:52am UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/1 "2016-03-07T07:52:53Z")

</div>

Hi,

At the time when the `slider button is pressed or released`, I would like to call a function. Is it possible?  
How can I this problem solve?

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [March 14, 2016, 12:03pm UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/2 "2016-03-14T12:03:44Z")

</div>

I’m not sure what you mean by “slider button”. You can use the `Callback` action on order to call to a javascript function when activating a trigger. Here are two samples using a switch and a button:

```auto
<!-- for button we use the clicked trigger -->
<Button>
    <Clicked>
        <Callback Handler="{someJSFunction}" />
    </Clicked
</Button>

<!-- for switch we use the WhileTrue and WhileFalse triggers to handle the two states -->
<Switch>
    <WhileTrue>
        <Callback Handler="{someJSFunctionWhenSwitchedOn}"/>
    </WhileTrue>
    <WhileFalse>
           <Callback Handler="{someJSFunctionWhenSwitchedOff}"/>
    </WhileFalse>
</Switch>

```

I hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![Onur\_Baran](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/onur_baran/32/127_2.png) [@Onur\_Baran](https://forums.fusetools.com/u/Onur_Baran)\
**Post date:** [March 14, 2016, 1:57pm UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/3 "2016-03-14T13:57:59Z")

</div>

> **Kristian Hasselknippe wrote:**
> 
> I’m not sure what you mean by “slider button”. You can use the `Callback` action on order to call to a javascript function when activating a trigger. Here are two samples using a switch and a button:

I use slider property of `ValueChanged`. This function is making the API call. But in the movement function of each slider is making the API call. This API call is also performing a write operation on the database. I don’t want it. I need last value of slider. Can I get the last value of the slider?

---

<div class="post-metadata">

**Author:** ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)\
**Post date:** [March 14, 2016, 2:25pm UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/4 "2016-03-14T14:25:09Z")

</div>

Ah ok

Then you can try the `Released` trigger instead ([https://www.fusetools.com/learn/fuse/ux/fuse/gestures/released](https://www.fusetools.com/learn/fuse/ux/fuse/gestures/released))

```auto
<Slider>
    <Released>
        <Callback Handler="{yoruJSCallback}" />
    </Released>
</Slider>

```

---

<div class="post-metadata">

**Author:** ![Onur\_Baran](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/onur_baran/32/127_2.png) [@Onur\_Baran](https://forums.fusetools.com/u/Onur_Baran)\
**Post date:** [March 14, 2016, 3:07pm UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/5 "2016-03-14T15:07:15Z")

</div>

Thank you Kristian. It’s work. But I can’t get `args.value`.

#### Function

```auto
lampSliderValueChanged: function (args) {
  debug_log("lampSliderValueChange >>> slider_pos : " + args.value);
  debug_log("lampSliderValueChange >>> args.data.id: " + args.data.id);
}

```

#### Debug log

```auto
LOG: lampSliderValueChange >>> slider_pos : undefined
LOG: lampSliderValueChange >>> args.data.id: 16

```

---

<div class="post-metadata">

**Author:** ![Onur\_Baran](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/onur_baran/32/127_2.png) [@Onur\_Baran](https://forums.fusetools.com/u/Onur_Baran)\
**Post date:** [March 14, 2016, 4:04pm UTC](https://forums.fusetools.com/t/slider-button-is-pressed-or-released/3933/6 "2016-03-14T16:04:35Z")

</div>

I solved this problem this way:

```auto
<Slider Value="{dim_value}" ValueChanged="{SliderValueChanged}">
    <Released>
        <Callback Handler="{SliderReleased}" />
    </Released>
</Slider>

```

```auto
var slider_pos = Observable(0);
...
...
SliderReleased: function (args) {
    if ( (slider_pos.value < 1) ? send_to_api(args.data.id, "0") : send_to_api(args.data.id, slider_pos.value) );},
SliderValueChanged: function (args) {
    var _slider_pos = 0;
    _slider_pos = args.value;
    slider_pos.value = _slider_pos.toFixed(0);

    debug_log("SLIDER_POS" + slider_pos.value);
}

```
