I have been handed over an application that I did not create and am fairly new to javascript. My problem is a simple calculation formVal1 = ((1000000 - formVal3) + formVal2) * .0096 I discovered that + is concatenated when adding strings so I need to convert formVal2 to a number. I've tried several things but nothing works.
Thanks!
</script>
<script language = JavaScript>
function CalculateMWh(formItem1,formItem2,formItem3,formItem4) {
var formVal1 = document.getElementById(formItem1).value;
var formVal2 = document.getElementById(formItem2).value;
var formVal3 = document.getElementById(formItem3).value;
var formVal4 = document.getElementById(formItem4).value;
// if (document.getElementById(formItem1).type != 'hidden')
if (formItem1 == 'P8_STDBY_2_AMT' || formItem1 == 'P8_STDBY_MWH')
{
if (document.getElementById(formItem4).value != 107)
{
formVal1 = ((1000000 - formVal3) + formVal2) * .0096
}
else
{
formVal1 = formVal2-formVal3;
}
}
else
{
formVal1 = formVal2-formVal3;
}
document.getElementById(formItem1).value = formVal1;
if (formVal4 == 'P8_AUX_2_AMT')
{
document.getElementById(formItem4).value = formVal1
}
}</script>
Thanks!
</script>
<script language = JavaScript>
function CalculateMWh(formItem1,formItem2,formItem3,formItem4) {
var formVal1 = document.getElementById(formItem1).value;
var formVal2 = document.getElementById(formItem2).value;
var formVal3 = document.getElementById(formItem3).value;
var formVal4 = document.getElementById(formItem4).value;
// if (document.getElementById(formItem1).type != 'hidden')
if (formItem1 == 'P8_STDBY_2_AMT' || formItem1 == 'P8_STDBY_MWH')
{
if (document.getElementById(formItem4).value != 107)
{
formVal1 = ((1000000 - formVal3) + formVal2) * .0096
}
else
{
formVal1 = formVal2-formVal3;
}
}
else
{
formVal1 = formVal2-formVal3;
}
document.getElementById(formItem1).value = formVal1;
if (formVal4 == 'P8_AUX_2_AMT')
{
document.getElementById(formItem4).value = formVal1
}
}</script>