I have a case where I'd like to be able to allow the users to change their units system. In doing so I would have to go through the entire page and:
a) change the units description from text and
b) convert the current values to the new units.
The first part I can achieve ok using getElementById and innerHTML. Its the second part I am having difficulty with
Example - I have two entries with units of "GIIP (BCF):" and values of 235 and 100 respectively;
<table id="table2">
<tr><input id="calc" type="button" value="Test Convert" onClick="conversion();" />
<td class="leftcol" id=test_units1>GIIP (BCF):</td>
<td><input id=test_value1 size="7" type="number" value="235"> </td>
<td class="leftcol" id=test_units2>GIIP (BCF):</td>
<td><input id=test_value2 size="7" type="number" value="100" > </td></table>
When I click the button, the following executes (where for the example I want to change the units description and simply double the existing value);
function conversion() {
for (var i = 1, e; e = document.getElementById("test_units" + i); ++i)
e.innerHTML = "m<sup>3</sup>";
convert_values();
}
function convert_values() {
for (var i = 1, e; e = parseFloat(document.getValueById("test_value" + i)); ++i)
var val = (e*2).toString();
e.innerHTML = val;
}
The units description converts OK, but the values are unaffected. Can anyone suggest a method to convert the values in a more elegant fashion (or indeed at all!). Bear in mind that I'll have many of these conversions to do on any one page/form.