F
farouqdin
Hi everyone,
I've just developed little code which calculates a certain score
depending on there values. The javascript works in the form. However
when i tried putting on to an external javascript document
("parScore.js"). It doesn't calculate the way it suppose to. Its like
it needs the reference from the form fields :s
I've referenced it as this in the html....
<script src="javascript/parScore.js"></script>
My javascript file contains this code....
<!--
// variables to hold the values of basic obs
var vHR = document.getElementById('HR').value;
var vTemp = document.getElementById('Temp').value;
var vRespRate = document.getElementById('RespRate').value;
var vBP = document.getElementById('BP').value;
var vSa02 = document.getElementById('Sa02').value;
var vGCS = document.getElementById('GCS').value;
var vUrineOutput = document.getElementById('UrineOutput').value;
var vLevelOfCons = document.getElementById('LevelOfCons').value;
var vO2Stat = document.getElementById('O2Stat').value;
//variables to hold the score
var vScoreHR;
var vScoreTemp;
var vScoreRespRate;
var vScoreBP;
var vScoreSa02;
var vScoreGCS;
var vScoreUrineOutput;
var vScoreLevelOfCons;
var vScoreO2Stat;
// PARSCORE
var vParScore
function CalcuateParScore() {
//----------HR CALC
if (vHR >= 51 && vHR <= 100)
{
vScoreHR = 0;
}
else if (vHR >= 41 && vHR <= 50)
{
vScoreHR = 1;
}
else if (vHR <= 40)
{
vScoreHR = 2;
}
else if (vHR >= 101 && vHR <= 110)
{
vScoreHR = 1;
}
else if (vHR >= 111 && vHR <= 129)
{
vScoreHR = 2;
}
else if (vHR >= 130)
{
vScoreHR = 3;
}
else
{
vScoreHR = 0;
}
//----------HR CALC
if (vTemp >= 36 && vTemp <= 37.5)
{
vScoreTemp = 0;
}
else if (vTemp >= 37.6 && vTemp <= 38.4)
{
vScoreTemp = 1;
}
else if (vTemp >= 38.5)
{
vScoreTemp = 2;
}
else if (vTemp >= 35.1 && vTemp <= 35.9)
{
vScoreTemp = 1;
}
else if (vTemp <= 35)
{
vScoreTemp = 2;
}
else
{
vScoreTemp = 0;
}
//--------RESPIRATORY RATE
if (vRespRate <= 8)
{
vScoreRespRate = 2;
}
else if (vRespRate >= 9 && vRespRate <= 24)
{
vScoreRespRate = 0;
}
else if (vRespRate >= 25 && vRespRate <= 29)
{
vScoreRespRate = 2;
}
else if (vRespRate >= 30)
{
vScoreRespRate = 3;
}
else
{
vScoreRespRate = 0;
}
//--------BP
if (vBP >= 101 && vBP <= 199)
{
vScoreBP = 0;
}
else if (vBP >= 200)
{
vScoreBP = 2;
}
else if (vBP >= 81 && vBP <= 100)
{
vScoreBP = 1;
}
else if (vBP >= 71 && vBP <= 80)
{
vScoreBP = 2;
}
else if (vBP <= 70)
{
vScoreBP = 3;
}
else
{
vScoreBP = 0;
}
//--------OXYGEN SATS
if (vSa02 >= 91 && vSa02 <= 94)
{
vScoreSa02 = 1;
}
else if (vSa02 >= 95)
{
vScoreSa02 = 0;
}
else if (vSa02 >= 89 && vSa02 <= 90)
{
vScoreSa02 = 2;
}
else if (vSa02 <= 88)
{
vScoreSa02 = 3;
}
else
{
vScoreSa02 = 0;
}
//--------OXYGEN SATS
if (vO2Stat == ">=8 Lits/40%")
{
vScoreO2Stat = 1;
}
else
{
vScoreO2Stat = 0;
}
//--------Urine Output
if (vUrineOutput == "<=20ml/hr for 2hrs")
{
vScoreUrineOutput = 3;
}
else if (vUrineOutput == "<=1ml/kg over for 2hrs")
{
vScoreUrineOutput = 2;
}
else if (vUrineOutput == ">=500ml in 24hrs")
{
vScoreUrineOutput = 0;
}
else if (vUrineOutput == "250-500mls in 24 hrs")
{
vScoreUrineOutput = 1;
}
else if (vUrineOutput == "<=250mls in 24 hrs")
{
vScoreUrineOutput = 2;
}
else if (vUrineOutput == "Nil")
{
vScoreUrineOutput = 3;
}
else
{
vScoreUrineOutput = 0;
}
//--------LEVEL OF CONCSCIOUSNESS
if (vLevelOfCons == "Alert")
{
vScoreLevelOfCons = 0;
}
else if (vLevelOfCons == "Drowsy Responds to voice")
{
vScoreLevelOfCons = 1;
}
else if (vLevelOfCons == "Acute confusion or agitation")
{
vScoreLevelOfCons = 2;
}
else if (vLevelOfCons == "Responds to pain only")
{
vScoreLevelOfCons = 3;
}
else
{
vScoreLevelOfCons = 0;
}
// Adding the parscore for each vital ob
vParScore = vScoreHR + vScoreTemp + vScoreRespRate + vScoreBP +
vScoreSa02 + vScoreO2Stat + vScoreUrineOutput + vScoreLevelOfCons
//Displaying the result into the parscore field
alert(vParScore);
document.getElementById('Parscore').value = vParScore;
//document.myform.ParScore.value=vHR
}
-->
The code does work in the html file. But to an external .js file it
does put something in the parscore field and msgbox does appear. But i
get the value 0 all the time. Regardless of me filling in the fields
in the html form.
Have i missed something out?
cheers
Farouq
I've just developed little code which calculates a certain score
depending on there values. The javascript works in the form. However
when i tried putting on to an external javascript document
("parScore.js"). It doesn't calculate the way it suppose to. Its like
it needs the reference from the form fields :s
I've referenced it as this in the html....
<script src="javascript/parScore.js"></script>
My javascript file contains this code....
<!--
// variables to hold the values of basic obs
var vHR = document.getElementById('HR').value;
var vTemp = document.getElementById('Temp').value;
var vRespRate = document.getElementById('RespRate').value;
var vBP = document.getElementById('BP').value;
var vSa02 = document.getElementById('Sa02').value;
var vGCS = document.getElementById('GCS').value;
var vUrineOutput = document.getElementById('UrineOutput').value;
var vLevelOfCons = document.getElementById('LevelOfCons').value;
var vO2Stat = document.getElementById('O2Stat').value;
//variables to hold the score
var vScoreHR;
var vScoreTemp;
var vScoreRespRate;
var vScoreBP;
var vScoreSa02;
var vScoreGCS;
var vScoreUrineOutput;
var vScoreLevelOfCons;
var vScoreO2Stat;
// PARSCORE
var vParScore
function CalcuateParScore() {
//----------HR CALC
if (vHR >= 51 && vHR <= 100)
{
vScoreHR = 0;
}
else if (vHR >= 41 && vHR <= 50)
{
vScoreHR = 1;
}
else if (vHR <= 40)
{
vScoreHR = 2;
}
else if (vHR >= 101 && vHR <= 110)
{
vScoreHR = 1;
}
else if (vHR >= 111 && vHR <= 129)
{
vScoreHR = 2;
}
else if (vHR >= 130)
{
vScoreHR = 3;
}
else
{
vScoreHR = 0;
}
//----------HR CALC
if (vTemp >= 36 && vTemp <= 37.5)
{
vScoreTemp = 0;
}
else if (vTemp >= 37.6 && vTemp <= 38.4)
{
vScoreTemp = 1;
}
else if (vTemp >= 38.5)
{
vScoreTemp = 2;
}
else if (vTemp >= 35.1 && vTemp <= 35.9)
{
vScoreTemp = 1;
}
else if (vTemp <= 35)
{
vScoreTemp = 2;
}
else
{
vScoreTemp = 0;
}
//--------RESPIRATORY RATE
if (vRespRate <= 8)
{
vScoreRespRate = 2;
}
else if (vRespRate >= 9 && vRespRate <= 24)
{
vScoreRespRate = 0;
}
else if (vRespRate >= 25 && vRespRate <= 29)
{
vScoreRespRate = 2;
}
else if (vRespRate >= 30)
{
vScoreRespRate = 3;
}
else
{
vScoreRespRate = 0;
}
//--------BP
if (vBP >= 101 && vBP <= 199)
{
vScoreBP = 0;
}
else if (vBP >= 200)
{
vScoreBP = 2;
}
else if (vBP >= 81 && vBP <= 100)
{
vScoreBP = 1;
}
else if (vBP >= 71 && vBP <= 80)
{
vScoreBP = 2;
}
else if (vBP <= 70)
{
vScoreBP = 3;
}
else
{
vScoreBP = 0;
}
//--------OXYGEN SATS
if (vSa02 >= 91 && vSa02 <= 94)
{
vScoreSa02 = 1;
}
else if (vSa02 >= 95)
{
vScoreSa02 = 0;
}
else if (vSa02 >= 89 && vSa02 <= 90)
{
vScoreSa02 = 2;
}
else if (vSa02 <= 88)
{
vScoreSa02 = 3;
}
else
{
vScoreSa02 = 0;
}
//--------OXYGEN SATS
if (vO2Stat == ">=8 Lits/40%")
{
vScoreO2Stat = 1;
}
else
{
vScoreO2Stat = 0;
}
//--------Urine Output
if (vUrineOutput == "<=20ml/hr for 2hrs")
{
vScoreUrineOutput = 3;
}
else if (vUrineOutput == "<=1ml/kg over for 2hrs")
{
vScoreUrineOutput = 2;
}
else if (vUrineOutput == ">=500ml in 24hrs")
{
vScoreUrineOutput = 0;
}
else if (vUrineOutput == "250-500mls in 24 hrs")
{
vScoreUrineOutput = 1;
}
else if (vUrineOutput == "<=250mls in 24 hrs")
{
vScoreUrineOutput = 2;
}
else if (vUrineOutput == "Nil")
{
vScoreUrineOutput = 3;
}
else
{
vScoreUrineOutput = 0;
}
//--------LEVEL OF CONCSCIOUSNESS
if (vLevelOfCons == "Alert")
{
vScoreLevelOfCons = 0;
}
else if (vLevelOfCons == "Drowsy Responds to voice")
{
vScoreLevelOfCons = 1;
}
else if (vLevelOfCons == "Acute confusion or agitation")
{
vScoreLevelOfCons = 2;
}
else if (vLevelOfCons == "Responds to pain only")
{
vScoreLevelOfCons = 3;
}
else
{
vScoreLevelOfCons = 0;
}
// Adding the parscore for each vital ob
vParScore = vScoreHR + vScoreTemp + vScoreRespRate + vScoreBP +
vScoreSa02 + vScoreO2Stat + vScoreUrineOutput + vScoreLevelOfCons
//Displaying the result into the parscore field
alert(vParScore);
document.getElementById('Parscore').value = vParScore;
//document.myform.ParScore.value=vHR
}
-->
The code does work in the html file. But to an external .js file it
does put something in the parscore field and msgbox does appear. But i
get the value 0 all the time. Regardless of me filling in the fields
in the html form.
Have i missed something out?
cheers
Farouq