...

View Full Version : Simple JavaScript help for nooby guy



NoobyMadDoc
08-28-2010, 03:17 PM
Hi,

Am new to this forum and even newer to java. I was trying to make a simple code for a form calculation, as always i end up failing :( Can any one tell me where i went wrong with this script?

JAVA Script

function meldCalc(form) {
var PBil = form.PBil.value;
var PINR = form.PINR.value;
var PCr = form.PCr.value;


if (!checkNum(PBil,"serum bilirubin")) {
form.PBil.select();
form.PBil.focus();
return false
}

if (!checkNum(PINR,"blood inr")) {
form.PINR.focus();
form.PINR.select();
return false
}

if (!checkNum(PCr,"plasma creatinine")) {
form.PCr.select();
form.PCr.focus();
return false
}



var meld = (0.957 * (Pcr) + 0.378 * (PBil) + 1.120 * (PINR) + 0.643 ) * 10;
form.meld.value = meld;



return true;
}

HTML CODE

<form name="meld" method=post>
<table border=0 bgcolor="" cellspacing=0 cellpadding=3>
<tr>
<th align=left class=tdtext>
Bilirubin:
</th>
<td>&nbsp;</td>
</tr>

<tr>
<td align=right class=tdtext>
Serum (P<sub>Bil</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PBil">
mg/dL
</td>
</tr>

<tr>
<th align=left class=tdtext>
INR:
</th>
<td>&nbsp;</td>
</tr>

<tr>
<td align=right class=tdtext>
Blood (P<sub>INR</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PINR">
Number
</td>
</tr>

<tr bgcolor="">
<th align=left class=tdtext>
Creatinine:
</th>
<td>&nbsp;</td>

</tr>
<tr bgcolor="">
<td align=right class=tdtext>
Serum (P<sub>Cr</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PCr">
mg/dl
</td>

</tr>





<tr bgcolor="">
<td>&nbsp;</td>

<td align=center>
<input type=button name=button value="Get MELD"
onClick="meldCalc(this.form)">
</td>
</tr>

<tr bgcolor="#cccccc">
<th align=right class=tdtext style="font-size:0.12in;">

MELD =
</th>

<td align=left class=tdtext>
<input type=text value="" size="3" maxlength="3" name="meld">

</td>

</tr>

Thx in advance for any help, :thumbsup:

vwphillips
08-28-2010, 03:31 PM
you will need to post function 'checkNum'

NoobyMadDoc
08-28-2010, 04:16 PM
ty phil,i tried to add this, if this is what you mean, sorry i have no clue about the intricacies involved, i just put em together and hope it works :(

function checkNum(val,text) {
if ((val == null) || (isNaN(val)) || (val == "") || (val < 0)) {
alert("Please enter a " + text + " concentration.");
return false
}
return true;
}


i put it there but its still not working :(

vwphillips
08-28-2010, 04:35 PM
Correction in RED


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function checkNum(val,text) {
if ((val == null) || (isNaN(val)) || (val == "") || (val < 0)) {
alert("Please enter a " + text + " concentration.");
return false
}
return true;
}

function meldCalc(form) {
var PBil = form.PBil.value;
var PINR = form.PINR.value;
var PCr = form.PCr.value;


if (!checkNum(PBil,"serum bilirubin")) {
form.PBil.select();
form.PBil.focus();
return false
}

if (!checkNum(PINR,"blood inr")) {
form.PINR.focus();
form.PINR.select();
return false
}

if (!checkNum(PCr,"plasma creatinine")) {
form.PCr.select();
form.PCr.focus();
return false
}



var meld = (0.957 * (PCr) + 0.378 * (PBil) + 1.120 * (PINR) + 0.643 ) * 10;
form.meld.value = meld;



return true;
}/*]]>*/
</script></head>

<body>
<form name="meld" method=post>
<table border=0 bgcolor="" cellspacing=0 cellpadding=3>
<tr>
<th align=left class=tdtext>
Bilirubin:
</th>
<td>&nbsp;</td>
</tr>

<tr>
<td align=right class=tdtext>
Serum (P<sub>Bil</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PBil">
mg/dL
</td>
</tr>

<tr>
<th align=left class=tdtext>
INR:
</th>
<td>&nbsp;</td>
</tr>

<tr>
<td align=right class=tdtext>
Blood (P<sub>INR</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PINR">
Number
</td>
</tr>

<tr bgcolor="">
<th align=left class=tdtext>
Creatinine:
</th>
<td>&nbsp;</td>

</tr>
<tr bgcolor="">
<td align=right class=tdtext>
Serum (P<sub>Cr</sub>):
</td>

<td align=left class=tdtext>
<input type=text value="" size="4" maxlength="4" name="PCr">
mg/dl
</td>

</tr>





<tr bgcolor="">
<td>&nbsp;</td>

<td align=center>
<input type=button name=button value="Get MELD"
onClick="meldCalc(this.form)">
</td>
</tr>

<tr bgcolor="#cccccc">
<th align=right class=tdtext style="font-size:0.12in;">

MELD =
</th>

<td align=left class=tdtext>
<input type=text value="" size="3" maxlength="3" name="meld">

</td>

</tr>
</body>

</html>

NoobyMadDoc
08-28-2010, 05:20 PM
thx again phil :)


i now get the values but i m making a mistake some where else i guess

i was trying to recreate this equation as an exercise http://www.mdcalc.com/meld-score-model-for-end-stage-liver-disease-12-and-older

its too complicated for me it seems :(



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum