How should I go about pushing the value of a variable to an input value with Javascript? I know is possible to set other element attributes with setAttribute but I can’t get anything to set in the “value”.
Here’s the current javascript function:
function testfunc(){
document.getElementsByTagName("meter")[0].setAttribute("value", "2000");
}
And the HTML:
<!doctype html>
<head>
<meta charset="utf-8">
<title>untitled</title>
</head>
<body>
<div id="container">
<button onclick="testfunc()">Find my elevations</button>
<meter value="900" min="0" max="5280" id="high">500/5280</meter>
</div>
</body>
</html>
What i’d like to do is replace the current set value of 900 with the testfunc() value of 2000. The 2000 is completely arbitrary as it will be a dynamically generated number in the live app.
HTML 5: 4.10.17 The meter element suggests that you can just do
The relevant portions of that spec are