# Newbie question: Update sliders from code, not UI

**URL:** https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623
**Category:** Uncategorized
**Created:** [April 10, 2018, 5:46pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623 "2018-04-10T17:46:15Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://talk.observablehq.com/u/Andrew)
#### Post date: [April 10, 2018, 5:46pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623/1 "2018-04-10T17:46:15Z")

</div>

I’m still getting my feet wet here. Using the `inputs` library from @jashkenas, I’ve created some sliders as in the code below (the `import` statement is actually in its own cell at the bottom of the notebook - I just put it here for completeness). Suppose that the values are mathematically related, so when any slider is adjusted, I get notified that a change has occurred and which slider was adjusted, and then I compute new values for the other sliders. I want to set the other sliders to display these new values. I’ve not been able to work this out from the docs, examples, or doing tests. Can someone please show me the way?

```javascript
import @jashkenas/inputs
viewof value_A = slider({min: -20, max: 20, value: 1})
viewof value_B = slider({min: -20, max: 20, value: 1})
viewof value_C = slider({min: -20, max: 20, value: 1})

```

---

<div class="post-metadata">

### Author: ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)
#### Post date: [April 10, 2018, 5:49pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623/2 "2018-04-10T17:49:38Z")

</div>

Hi Andrew,

A couple of weeks ago, we had a similar question about wiring up multiple sliders that can affect each other in a more or less circular fashion.

Take a look at the notebooks linked here: [Mutable values with multiple setters "bounce" forever](https://talk.observablehq.com/t/mutable-values-with-multiple-setters-bounce-forever/560/2)

… and then let me know if you still have questions. Or! feel free to link the notebook that isn’t working for you yet.

---

<div class="post-metadata">

### Author: ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://talk.observablehq.com/u/Andrew)
#### Post date: [April 10, 2018, 7:57pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623/3 "2018-04-10T19:57:16Z")

</div>

Thank you! I’ve tried to replicate that using your `slider()` routine. This doesn’t give me any errors, but it doesn’t update the slider, either! I’m not sure how to link to a private notebook - here’s the URL I see in my browser: [https://beta.observablehq.com/d/fae8e01fa16acdb1](https://beta.observablehq.com/d/fae8e01fa16acdb1) If that doesn’t work, here’s the essential bit of the code. These two lines are in different cells. When I adjust the slider for `line_A`, I’d expect to see the slider for `line_b` move in response, but that slider does not update.

```javascript
viewof line_A = slider({min: -20, max: 20, value: 1})
viewof line_m = slider({min: -20, max: 20, value: "${this ? line_A+1 : line_A / 2}"})

```

---

<div class="post-metadata">

### Author: ![jashkenas](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/jashkenas/32/1778_2.png) [@jashkenas](https://talk.observablehq.com/u/jashkenas)
#### Post date: [April 10, 2018, 8:01pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623/4 "2018-04-10T20:01:43Z")

</div>

I’m afraid we can’t view your draft notebooks, but…

That looks like a simple `"` versus ` thing to me.

```auto
viewof line_m = slider({min: -20, max: 20, value: `${this ? line_A+1 : line_A / 2}`})

```

See a working example here:

> **[Slider Question (for the forums)](https://observablehq.com/@jashkenas/slider-question-for-the-forums)**
>
> An Observable notebook by Jeremy Ashkenas.

---

<div class="post-metadata">

### Author: ![Andrew](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@Andrew](https://talk.observablehq.com/u/Andrew)
#### Post date: [April 10, 2018, 10:25pm UTC](https://talk.observablehq.com/t/newbie-question-update-sliders-from-code-not-ui/623/5 "2018-04-10T22:25:43Z")

</div>

Thank you! Right, backticks for template literals. I clearly need to refresh my Javascript chops.
