jQuery addClass example
Change class name on click in jQuery
by Scoobler
HTML
<div id="banner-message">
<button>Calculate</button><br />
Max Loadstep: <input type="text" id="i_Max_Loadstep" value="200" />200<br />
No LB's Online: <input type="text" id="i_LB_Online" value="1" />1<br />
MAN Mode (0=OFF / 1=ON): <input type="text" id="i_Man_Mode" value="0" />0<br />
Deviation: <input type="text" id="i_Loadstep_Required" value="600" />600<br />
Limit Loadstep (0=OFF / 1=ON): <input type="text" id="i_Limit_Step_Enabled" value="1" />1<br />
LB10 Online (0=OFF / 1=ON): <input type="text" id="i_LB10_Enabled" value="1" />1<br />
Current Load: <input type="text" id="i_Load" value="1200" />1200<br />
LB10 Current Load: <input type="text" id="i_LB10_Setpoint" value="900" />900<br />
</div>
.....
<div id="banner-message">
New Load: <span id="o_Load"></span><br />
Loadstep: <span id="o_Loadstep"></span><br /><br />
Process: <br /><span id="o_Process"></span>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
margin: 0 auto;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
// find elements
var button = $("button")
// handle click and add class
button.on("click", function(){
var x_Loadstep_LBs = 0, x_Load = 0, x_LB10_Loadstep = 0, x_LBs_Loadstep = 0, x_LBs_Load = 0;
var i_Max_Loadstep = parseInt($('#i_Max_Loadstep').val());
var i_LB_Online = parseInt($('#i_LB_Online').val());
var i_Man_Mode = parseInt($('#i_Man_Mode').val());
var i_Loadstep_Required = parseInt($('#i_Loadstep_Required').val());
var i_Limit_Step_Enabled = parseInt($('#i_Limit_Step_Enabled').val());
var i_LB10_Enabled = parseInt($('#i_LB10_Enabled').val());
var i_Load = parseInt($('#i_Load').val());
var i_LB10_Setpoint = parseInt($('#i_LB10_Setpoint').val());
$('#o_Process').html('');
x_Loadstep_LBs = i_Max_Loadstep * i_LB_Online;
addMsg('Max LB\'s Loadstep calculated at: ' + x_Loadstep_LBs);
if (i_Man_Mode === 1) {
addMsg('Running in MAN mode, don\'t apply limits.')
x_Load = i_Loadstep_Required;
} else {
if (i_Limit_Step_Enabled === 0) {
addMsg('Limit loadstep is disabled.');
x_Load = i_Loadstep_Required;
} else {
if (i_Loadstep_Required < i_Max_Loadstep) {
addMsg('Loadstep is less than the maximum loadstep.');
x_Load = i_Loadstep_Required;
} else {
if (i_LB10_Enabled === 0) {
addMsg('LB10 is not online.')
if (i_Loadstep_Required < x_Loadstep_LBs) {
addMsg('Loadstep required is less than the max loadstep on the LB\'s.')
x_Load = i_Loadstep_Required;
} else {
addMsg('Loadstep required exceeded max loadstep on the LB\'s so only applied max step.')
x_Load = x_Loadstep_LBs;
}
} else {
x_LB10_Loadstep = i_Loadstep_Required - (i_Load - i_LB10_Setpoint);
addMsg('Calculated LB10\'s loadstep to be: ' + x_LB10_Loadstep);
if (x_LB10_Loadstep < 0) {
addMsg('As the amount to be removed from LB10 is negative, that means no load needs to be removed from...