Bryan Hepworth said:
Hi Everyone
I'm wondering what the best practice is for a particular task I'm trying to
accomplish. I'm using two sets of radio buttons for a user to select values
from. These values then go into a couple of tables to show some heat loss
calculations depending on the values chosen I want the tables to have the
relevant values filled in. Is the best way to accomplish this a long list of
if then else type statements or is there a better way of doing this?
http://www.redfedora.co.uk/jscriptradio.html
If anyone could point me in the right direction I'd be really grateful.
Here's an example using a 3-dimensional array as a lookup table:
<script type="text/javascript">
var globalFurnaceTemp=0;
var globalFurnaceLining=0;
var table=[]
table[900]=[];
table[1050]=[];
table[1150]=[];
table[1250]=[];
table[900][200]=[72,64,20,64,20];
table[900][230]=[110,90,28,64,60];
table[900][343]=[99,84,24,64,53];
table[900][457]=[91,79,22,64,45]
table[1050][200]=[86,75,20,75,20];
table[1050][230]=[124,104,25,75,56];
table[1050][343]=[112,96,22,75,49];
table[1050][457]=[103,90,24,75,41];
table[1150][200]=[96,84,20,84,20];
table[1150][230]=[134,114,24,84,54];
table[1150][343]=[121,105,21,84,45];
table[1150][457]=[111,98,20,93,20];
table[1250][200]=[107,93,20,93,20];
table[1250][230]=[144,124,22,93,51];
table[1250][343]=[130,144,19,93,42];
table[1250][457]=[119,106,17,93,33];
function checktemperature(furnacetemp)
{
globalFurnaceTemp=parseInt(furnacetemp);
document.getElementById('myCurrentFurnace').rows[1].cells[0].innerHTML=furnacetemp
// Align Centre - note spelling! - Cell Temperature current furnace
document.getElementById('myCurrentFurnace').rows[1].cells[0].align="center"
document.getElementById('myProposedNewFurnace1').rows[1].cells[0].innerHTML=furnacetemp
// Align Centre - note spelling! - Cell Temperature additional 50mm module
document.getElementById('myProposedNewFurnace1').rows[1].cells[0].align="center"
document.getElementById('myProposedNewFurnace2').rows[1].cells[0].innerHTML=furnacetemp
// Align Centre - note spelling! - Cell Temperature 250mm module conversion
document.getElementById('myProposedNewFurnace2').rows[1].cells[0].align="center"
}
function checklining(furnacelining)
{
globalFurnaceLining=parseInt(furnacelining);
document.getElementById('myCurrentFurnace').rows[1].cells[1].innerHTML=furnacelining
// Align Centre - note spelling! - Cell Furnace Lining current furnace
document.getElementById('myCurrentFurnace').rows[1].cells[1].align="center"
document.getElementById('myProposedNewFurnace1').rows[1].cells[1].innerHTML=furnacelining
// Align Centre - note spelling! - Cell Furnace Lining additional 50mm module
document.getElementById('myProposedNewFurnace1').rows[1].cells[1].align="center"
document.getElementById('myProposedNewFurnace2').rows[1].cells[1].innerHTML=furnacelining
// Align Centre - note spelling! - Cell Furnace Lining 250mm module conversion
document.getElementById('myProposedNewFurnace2').rows[1].cells[1].align="center"
// Turn the Current Furnace Cold Face Temperature Cell Red
document.getElementById("myCurrentFurnace").rows[1].cells[2].style.background =
"#FF9900"
// Turn the 50mm Module Addition % Saving Cell Red
document.getElementById("myProposedNewFurnace1").rows[1].cells[3].style.background
= "#FF9900"
// Turn the 250mm Module Conversion % Saving Cell Red
document.getElementById("myProposedNewFurnace2").rows[1].cells[3].style.background
= "#FF9900"
}
function docalculation()
{
if(table[globalFurnaceTemp][globalFurnaceLining]) {
var lookup=table[globalFurnaceTemp][globalFurnaceLining];
var current=document.getElementById('myCurrentFurnace');
var prop1=document.getElementById('myProposedNewFurnace1');
var prop2=document.getElementById('myProposedNewFurnace2');
current.rows[1].cells[2].innerHTML=lookup[0];
prop1.rows[1].cells[2].innerHTML=lookup[1];
prop1.rows[1].cells[3].innerHTML=lookup[2];
prop2.rows[1].cells[2].innerHTML=lookup[3];
prop2.rows[1].cells[3].innerHTML=lookup[4];
current.rows[1].cells[2].align="center"
prop1.rows[1].cells[2].align="center"
prop1.rows[1].cells[3].align="center"
prop2.rows[1].cells[2].align="center"
prop2.rows[1].cells[3].align="center"
}
}
</script>
--