Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Simple JavaScript help for nooby guy

    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
    Code:
    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
    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,

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,533
    Thanks
    3
    Thanked 512 Times in 499 Posts
    you will need to post function 'checkNum'
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thx phil

    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

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,533
    Thanks
    3
    Thanked 512 Times in 499 Posts
    Correction in RED

    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #5
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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-mod...e-12-and-older

    its too complicated for me it seems


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •