Hi! can someone help me with converting observablehq's viewof operator in javascript.

Joined
Apr 3, 2021
Messages
1
Reaction score
0
I want to get the result as shown below.

HTML:
<input oninput="myFunc()" type="range" id="myRange" min="0" max="100"/>

JS:
var a = document.getElementById("myRange");

function myFunc(){
b = document.getElementById("myRange").value;
return b;
}

const exp = b; //Output as input's value(updated-current).


//End

I want the value of b change dyanamically, like in observable as,




//Observable.

//*
{
const exp = b
}


//*
//slider is for demo only

viewof b = slider({
min: 0.5,
max: 8,
step: 0.1,
value: 5,
title: "n"
})

//*
b // Displays current value of rage input.

//END

('//*' is start cell and end cell in observablehq, here only for demo, )
 
Joined
Nov 27, 2019
Messages
163
Reaction score
28
Try this:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Enigma Room - Tarifs</title>

</head>
<body>
<input type="range" min="1" max="100" value="50" class="slider" id="Slider">
<div id="Value">50</div>

<script>

document.getElementById("Value").innerHTML = document.getElementById("Slider").value;

document.getElementById("Slider").oninput = function() {
    document.getElementById("Value").innerHTML = this.value;
}
</script>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top