I am modelling a nuclear reactor in JavaScript/HTML and am struggling with dynamic updates of the results I'm interested in.
Reactor temperature and reactor pressure are both dependent on both control rod height and coolant pump flow. Is there a way of having the resultant numbers displayed on the screen such that they will dynamically update as the user changes the inputs?
I can make this work with buttons to trigger the calculation of the temperature/pressure - but would rather have it on screen if possible!
Happy to use jQuery/AJAX solutions, but don't honestly know where to start or what it really is I would be asking them to do - I don't want to just get information from another page, I want to work out a constantly changing calculation.
Thank you!
HTML
<div id="Reactor">
<button onClick = "IncCRH()">Increase Control Rod Height</button>
<button onClick = "DecCRH()">Decrease Control Rod Height</button>
<div id="result"></div>
<br>
<button onClick="test()">Control Rod Height</button>
<br>
<br>
<button onClick = "IncCPF()">Increase Coolant Pump Flow</button>
<button onClick = "DecCPF()">Decrease Coolant Pump Flow</button>
<br>
<br>
<button onClick = "test2()"> Coolant Pump Flow</button>
<br>
<br>
<p id = "ReacTemp"></p>
<br>
<br>
<p id = "ReacPres"></p>
</div>
JavaScript
var ControlRodHeight = 50;
var CoolantPumpFlow = 20;
function IncCRH(){
user = ++ControlRodHeight;
if (ControlRodHeight > 100) {
ControlRodHeight = 100;
}
ReactorTemperature = (445 + (ControlRodHeight*4.5) -(CoolantPumpFlow*2.3));
ReactorPressure = (10 + (ControlRodHeight*1.36)-(CoolantPumpFlow*0.0065));
}
function DecCRH() {
user = --ControlRodHeight;
if (ControlRodHeight < 0) {
ControlRodHeight = 0
}
ReactorTemperature = (445 + (ControlRodHeight*4.5)-(CoolantPumpFlow*2.3));
ReactorPressure = (10 + (ControlRodHeight*1.36)-(CoolantPumpFlow*0.0065));
}
function test(){
alert (ControlRodHeight);
}
function IncCPF(){
user = ++CoolantPumpFlow;
if (CoolantPumpFlow > 40) {
CoolantPumpFlow = 40;
}
ReactorTemperature = (445 + (ControlRodHeight*4.5)-(CoolantPumpFlow*2.3));
ReactorPressure = (10 + (ControlRodHeight*1.36)-(CoolantPumpFlow*0.0065));
}
function DecCPF(){
user = --CoolantPumpFlow;
if (CoolantPumpFlow < 0) {
CoolantPumpFlow = 0;
}
ReactorTemperature = (445 + (ControlRodHeight*4.5) -(CoolantPumpFlow*2.3));
ReactorPressure = (10 + (ControlRodHeight*1.36)-(CoolantPumpFlow*0.0065));
}
function test2(){
alert (CoolantPumpFlow);
}
var ReacTemp = ReactorTemperature.toFixed(0);
document.getElementById("ReacTemp").innerHTML = "Reactor Temperature is " + ReacTemp
var ReacPres = ReactorPressure.toFixed(0);
document.getElementById("ReacPres").innerHTML = "Reactor Pressure is " + ReacPres