[Javascript] Dropdown to implement different functions problem
Andre Duszynski
andre.duszynski at adelaide.edu.au
Tue Jul 8 03:06:27 CDT 2003
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>
More information about the Javascript
mailing list