I have a JavaScript analogue gauge I'm trying to drive with live values elsewhere on the page that is dynamically updated. I want to display this value on the gauge.js
. Below is what I have, minus the form/post vals i would like to use. I suspect the highlighted lines 开发者_开发知识库below are not correctly formatted?
Thanks for the help cody
<script type="text/javascript">
function getReg(){
var regVal29 = document.getElementById('reg1029');
}
</script>
*************************
dc_amperage = new Gauge( document.getElementById( 'dc_amperage' ), {label: "DCAmperage"});
**dc_amperage.setValue(parseInt(var regVal29.value 10););**
Modify getReg
to the following:
function getReg() {
var reg_elem = document.getElementById('reg1029');
if (!reg_elem) {
throw new Error('No element found');
}
return reg_elem.value;
}
Then in your setValue
use:
try {
dc_amperage.setValue(parseInt(getReg(), 10));
} catch (err) {
//error handle
}
精彩评论