[Javascript] Dropdown to implement different functions proble m

Muchacho, Laurent (TWIi London) LMuchacho at twii.net
Tue Jul 8 04:43:04 CDT 2003


Hi Andre

First question when I see your code is: Where do you define the value of n
in the function process(t)?

function process(t) {
 if(n==0) alert("no choice made");
 if(n==1) calc_male(t);
 if(n==2) calc_female(t);
}

Sort this out and you will be saved I think

Laurent


-----Original Message-----
From: Andre Duszynski [mailto:andre.duszynski at adelaide.edu.au]
Sent: 08 July 2003 09:06
To: javascript at LaTech.edu
Subject: [Javascript] Dropdown to implement different functions problem



Hello all, i'm very much a newbie with regards to JS - please bear with
me !!

What i'm trying to achieve with the below code, is that if a user
selects the gender from the drop down list, and then fills in the values
for "age" and "height", the resulting click on the "Compute" button will
run either calc_male or calc_female to calculate the values of FEV and
FVC which are then updated on the form fields. I am sure that the
parent>child inheritance thang is the problem but am unsure of how to go
about it.

Thankyou,

Andre Duszynski.

----------


<html>
<head>
<title>Asthma Calculator</title>
</head>
<body>
<script language="JavaScript">

function process(t) {
 if(n==0) alert("no choice made");
 if(n==1) calc_male(t);
 if(n==2) calc_female(t);
}

function calc_male(t){
  var a1 = parseFloat(t.a1.value);
  var h1 = parseFloat(t.h1.value);
  var fev = (Math.round(((2.081) + (0.5846) * (h1*h1*h1) - (0.01599) *
(a1*h1))*100)/100);
  var fvc = (Math.round(((12.675) - (0.0002764) * (a1*a1) - (10.736) +
(h1*h1*h1))*100)/100);
  t.fev_val.value = (fev);
  t.fvc_val.value = (fvc);
  return true;
}

function calc_female(t){
  var a1 = parseFloat(t.a1.value);
  var h1 = parseFloat(t.h1.value);
  var fev = (Math.round(((1.597) + (0.5552) * (h1*h1*h1) - (0.01574) *
(a1*h1))*100)/100);
  var fvc = (Math.round(((-3.598) - (0.0002525) * (a1*a1) + (4.680) *
h1)*100)/100);
  t.fev_val.value = (fev);
  t.fvc_val.value = (fvc);
  return true;
}
</script>

<form name="t">
  <select name="parent" onClick="process(value)">
    <option value="0" selected>Gender</option>
    <option value="1">Male</option>
    <option value="2">Female</option>
  </select>

  <table>
    <tr>
      <td>age in years:
      <td><input name="a1" type=text size=10>
    </tr>
    <tr>
      <td>height in metres:
      <td><input name="h1" type=text size=10>
    </tr>
    </tr>
    <tr>
      <td>FEV1(L):
      <td><input name="fev_val" type=text size=4>
    </tr>
    <tr>
      <td>FVC(L):
      <td><input name="fvc_val" type=text size=4>	
    </tr>
    <tr>
      <td><input type="button" value="Compute" 
	onClick="return process(t);">
<td></tr>
  </table>
</form>
</body>
</html>
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


DISCLAIMER - The preceding e-mail message (including any attachments)
contains information that may be confidential, may be protected by the
attorney-client or other applicable privileges, or may constitute non-public
information.  It is intended to be conveyed only to the designated
recipient(s) named above.  If you are not an intended recipient of this
message, or have otherwise received it in error, please notify the sender by
replying to this message and then delete all copies of it from your computer
system.  Any use, dissemination, distribution, or reproduction of this
message by unintended recipients is not authorized and may be unlawful. The
contents of this communication do not necessarily represent the views of
this company.


More information about the Javascript mailing list