HTA:Javascript 计算器 - 添加新变量
HTA: Javascript calculator - adding new variables
我是一名神经外科医生,正在尝试更新大约四年前制作的 javascript 计算器。它采用有关颅内动脉瘤的许多变量,并根据三个不同的队列研究给出估计的破裂率。我正在尝试使用相同的方法包含一个包含更多变量的新元分析。不幸的是,当我添加新变量和 if 函数时,计算器坏了....
原来的计算器是这样工作的:http://www.timkilleen.com/calc1.html
<strong><large>Aneurysm Calculator - ISUIA</large></strong>
<br>
<br>
<script type="text/javascript">
function getRisk()
{
var size = window.document.getElementById('An_Size').value;
var location = window.document.getElementById('locate').value;
var ysah = window.document.getElementById('yessah');
var nsah = window.document.getElementById('nosah');
x=size;
y=location;
z=ysah.checked?"yes":"no";
if( x==0 ) output(" -- / --")
if( x>0&& x<7 && y=="ant" && z=="no" ) output(" 1 /0 ")
if( x>=7&& x<12 && y=="ant" && z=="no" ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25 && y=="ant" && z=="no" ) output(" 0.971 /14.5 ")
if( x>=25 && y=="ant" && z=="no" ) output(" 0.92 /40 ")
if( x>0&& x<7 && y=="post" && z=="no" ) output(" 0.995 /2.5 ")
if( x>=7&& x<12 && y=="post" && z=="no" ) output(" 0.971 /14.5 ")
if( x>=12&&x<25 && y=="post" && z=="no" ) output(" 0.9632 /18.4 ")
if( x>=25 && y=="post" && z=="no" ) output(" 0.9 /50 ")
if( x>0&& x<7 && y=="int" && z=="no" ) output(" 1 /0 ")
if( x>=7&& x<12 && y=="int" && z=="no" ) output(" 1 /0 ")
if( x>=12&&x<25 && y=="int" && z=="no" ) output(" 0.994 /3 ")
if( x>=25 && y=="int" && z=="no" ) output(" 0.9872 /6.4 ")
if( x>0&& x<7 && y=="ant" && z=="yes" ) output(" 0.997 /1.5 ")
if( x>=7&& x<12 && y=="ant" && z=="yes" ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25 && y=="ant" && z=="yes" ) output(" 0.971 /14.5 ")
if( x>=25 && y=="ant" && z=="yes" ) output(" 0.92 /40 ")
if( x>0&& x<7 && y=="post" && z=="yes" ) output(" 0.9932 /3.4 ")
if( x>=7&& x<12 && y=="post" && z=="yes" ) output(" 0.971 /14.5 ")
if( x>=12&&x<25 && y=="post" && z=="yes" ) output(" 0.9632 /18.4 ")
if( x>=25 && y=="post" && z=="yes" ) output(" 0.9 /50")
if( x>0&& x<7 && y=="int" && z=="yes" ) output(" 1 /0 ")
if( x>7&& x<12 && y=="int" && z=="yes" ) output(" 1 /0 ")
if( x>=12&&x<25 && y=="int" && z=="yes" ) output(" 0.994 /3 ")
if( x>=25 && y=="int" && z=="yes" ) output(" 0.9872 /6.4 ")
}
function output(str)
{
var arr = str.split("/");
var one_yr_risk = parseFloat(arr[0]);
var life_expectancy = parseFloat(window.document.getElementById('life_expectancy').value);
var cum_risk="--";
var five_yr_risk="--"
{
five_yr_risk = arr[1];
cum_risk = Math.round(((1-Math.pow((one_yr_risk), life_expectancy))*100)*10)/10;
}
window.document.getElementById('r2').value=five_yr_risk;
if(life_expectancy<10)
cum_risk="--";
if(cum_risk===0)
cum_risk="0*";
window.document.getElementById('r1').value=cum_risk;
}
</script>
<img alt="" src="/sites/default/files/COW.gif" style="width: 250px; height: 284px; border-width: 0px; border-style: solid; margin: 0px;" />
<form action="" id="riskform" onSubmit="return false;">
<fieldset>
<label for="locate">Location</label>
<select id="locate" name='locate'
onchange="getRisk()">
<option value="ant">Anterior circulation</option>
<option value="post">Posterior circulation (incl. PCom)</option>
<option value="int">Intracavernous</option>
</select>
<br>
<br>
<p>
<label class="inlinelabel" for='includeinscription'>
Size(mm)</label>
<input type="text" id="An_Size" size=7 onKeyUp="getRisk()"
name="size" value="0" />
</p>
<label >Previous SAH?</label>
<input type="radio" name="prevsah" value="yessah" id="yessah"
onclick="getRisk()" />
Yes
<input type="radio" name="prevsah" value="nosah" id="nosah"
onclick="getRisk()" />
No
<br>
<br>
<label for="Five_Year">5 Year Rupture Risk (%)</label>
<input type="text" name="val3" id="r2"><span id="result2"></span>
<p>
<p>
<br>
<label class="inlinelabel" for='includeinscription'>
Estimated life expectancy (minimum 10 years)</label>
<input type="text" id="life_expectancy" size=7 onKeyUp="getRisk()"
name="size" value="0" />
</p>
<label for="One_Year">Cumulative Lifetime Rupture Risk (%)</label>
<input type="text" name="val3" id="r1"><span id="result1"></span>
<div id="Final_Risk"></div>
</fieldset>
</form>
我添加了两个新的 yes/no 变量和一个额外的下拉选项(种族),它以指数方式增加了可能的 if 函数的大小(为简洁起见未包括在内,示例如下)。
if( x>=20 && y=="oth" && z=="no" && u=="yes" && v=="no" && w="jp" ) output(" 0.9644 /17.8 ")
新变量设置如下:
<script type="text/javascript">
function getRisk()
{
var size = window.document.getElementById('An_Size').value;
var location = window.document.getElementById('locate').value;
var ysah = window.document.getElementById('yessah');
var nsah = window.document.getElementById('nosah');
var eth = window.document.getElementById('ethno').value;
var osev = window.document.getElementById('oversev');
var usev = window.document.getElementById('undersev');
var yhtn = window.document.getElementById('yhyp');
var nhtn = window.document.getElementById('nhyp');
u=yhtn.checked?"yes":"no";
v=osev.checked?"yes":"no";
w=eth;
x=size;
y=location;
z=ysah.checked?"yes":"no";
我很确定我错误地实现了附加变量 and/or 在此处错误地设置了 html 表单:
</select>
</p>
<label >Previous SAH?</label>
<input type="radio" name="prevsah" value="yessah" id="yessah"
onclick="getRisk()" />
Yes
<input type="radio" name="prevsah" value="nosah" id="nosah"
onclick="getRisk()" />
No
<p>
<label >Hypertension?</label>
<input type="radio" name="htn" value="yhyp" id="yhyp"
onclick="getRisk()" />
Yes
<input type="radio" name="htn" value="nhyp" id="nhyp"
onclick="getRisk()" />
No
<p>
<label >Age over 70?</label>
<input type="radio" name="oversev" value="osev" id="osev"
onclick="getRisk()" />
Yes
<input type="radio" name="oversev" value="usev" id="usev"
onclick="getRisk()" />
No
<br>
如有任何建议,我们将不胜感激。
祝福,
蒂姆
检查了您的损坏代码。它在控制台上给出错误。 Uncaught ReferenceError: Invalid left-hand side in assignment
。尝试使用 w=="jp"
而不是 w="jp"
来满足您的所有条件。
并替换以下
var osev = window.document.getElementById('oversev');
var usev = window.document.getElementById('undersev');
和
var osev = window.document.getElementById('osev');
var usev = window.document.getElementById('usev');
您使用的 ID 有误。
我是一名神经外科医生,正在尝试更新大约四年前制作的 javascript 计算器。它采用有关颅内动脉瘤的许多变量,并根据三个不同的队列研究给出估计的破裂率。我正在尝试使用相同的方法包含一个包含更多变量的新元分析。不幸的是,当我添加新变量和 if 函数时,计算器坏了....
原来的计算器是这样工作的:http://www.timkilleen.com/calc1.html
<strong><large>Aneurysm Calculator - ISUIA</large></strong>
<br>
<br>
<script type="text/javascript">
function getRisk()
{
var size = window.document.getElementById('An_Size').value;
var location = window.document.getElementById('locate').value;
var ysah = window.document.getElementById('yessah');
var nsah = window.document.getElementById('nosah');
x=size;
y=location;
z=ysah.checked?"yes":"no";
if( x==0 ) output(" -- / --")
if( x>0&& x<7 && y=="ant" && z=="no" ) output(" 1 /0 ")
if( x>=7&& x<12 && y=="ant" && z=="no" ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25 && y=="ant" && z=="no" ) output(" 0.971 /14.5 ")
if( x>=25 && y=="ant" && z=="no" ) output(" 0.92 /40 ")
if( x>0&& x<7 && y=="post" && z=="no" ) output(" 0.995 /2.5 ")
if( x>=7&& x<12 && y=="post" && z=="no" ) output(" 0.971 /14.5 ")
if( x>=12&&x<25 && y=="post" && z=="no" ) output(" 0.9632 /18.4 ")
if( x>=25 && y=="post" && z=="no" ) output(" 0.9 /50 ")
if( x>0&& x<7 && y=="int" && z=="no" ) output(" 1 /0 ")
if( x>=7&& x<12 && y=="int" && z=="no" ) output(" 1 /0 ")
if( x>=12&&x<25 && y=="int" && z=="no" ) output(" 0.994 /3 ")
if( x>=25 && y=="int" && z=="no" ) output(" 0.9872 /6.4 ")
if( x>0&& x<7 && y=="ant" && z=="yes" ) output(" 0.997 /1.5 ")
if( x>=7&& x<12 && y=="ant" && z=="yes" ) output(" 0.9948 /2.6 ")
if( x>=12&&x<25 && y=="ant" && z=="yes" ) output(" 0.971 /14.5 ")
if( x>=25 && y=="ant" && z=="yes" ) output(" 0.92 /40 ")
if( x>0&& x<7 && y=="post" && z=="yes" ) output(" 0.9932 /3.4 ")
if( x>=7&& x<12 && y=="post" && z=="yes" ) output(" 0.971 /14.5 ")
if( x>=12&&x<25 && y=="post" && z=="yes" ) output(" 0.9632 /18.4 ")
if( x>=25 && y=="post" && z=="yes" ) output(" 0.9 /50")
if( x>0&& x<7 && y=="int" && z=="yes" ) output(" 1 /0 ")
if( x>7&& x<12 && y=="int" && z=="yes" ) output(" 1 /0 ")
if( x>=12&&x<25 && y=="int" && z=="yes" ) output(" 0.994 /3 ")
if( x>=25 && y=="int" && z=="yes" ) output(" 0.9872 /6.4 ")
}
function output(str)
{
var arr = str.split("/");
var one_yr_risk = parseFloat(arr[0]);
var life_expectancy = parseFloat(window.document.getElementById('life_expectancy').value);
var cum_risk="--";
var five_yr_risk="--"
{
five_yr_risk = arr[1];
cum_risk = Math.round(((1-Math.pow((one_yr_risk), life_expectancy))*100)*10)/10;
}
window.document.getElementById('r2').value=five_yr_risk;
if(life_expectancy<10)
cum_risk="--";
if(cum_risk===0)
cum_risk="0*";
window.document.getElementById('r1').value=cum_risk;
}
</script>
<img alt="" src="/sites/default/files/COW.gif" style="width: 250px; height: 284px; border-width: 0px; border-style: solid; margin: 0px;" />
<form action="" id="riskform" onSubmit="return false;">
<fieldset>
<label for="locate">Location</label>
<select id="locate" name='locate'
onchange="getRisk()">
<option value="ant">Anterior circulation</option>
<option value="post">Posterior circulation (incl. PCom)</option>
<option value="int">Intracavernous</option>
</select>
<br>
<br>
<p>
<label class="inlinelabel" for='includeinscription'>
Size(mm)</label>
<input type="text" id="An_Size" size=7 onKeyUp="getRisk()"
name="size" value="0" />
</p>
<label >Previous SAH?</label>
<input type="radio" name="prevsah" value="yessah" id="yessah"
onclick="getRisk()" />
Yes
<input type="radio" name="prevsah" value="nosah" id="nosah"
onclick="getRisk()" />
No
<br>
<br>
<label for="Five_Year">5 Year Rupture Risk (%)</label>
<input type="text" name="val3" id="r2"><span id="result2"></span>
<p>
<p>
<br>
<label class="inlinelabel" for='includeinscription'>
Estimated life expectancy (minimum 10 years)</label>
<input type="text" id="life_expectancy" size=7 onKeyUp="getRisk()"
name="size" value="0" />
</p>
<label for="One_Year">Cumulative Lifetime Rupture Risk (%)</label>
<input type="text" name="val3" id="r1"><span id="result1"></span>
<div id="Final_Risk"></div>
</fieldset>
</form>
我添加了两个新的 yes/no 变量和一个额外的下拉选项(种族),它以指数方式增加了可能的 if 函数的大小(为简洁起见未包括在内,示例如下)。
if( x>=20 && y=="oth" && z=="no" && u=="yes" && v=="no" && w="jp" ) output(" 0.9644 /17.8 ")
新变量设置如下:
<script type="text/javascript">
function getRisk()
{
var size = window.document.getElementById('An_Size').value;
var location = window.document.getElementById('locate').value;
var ysah = window.document.getElementById('yessah');
var nsah = window.document.getElementById('nosah');
var eth = window.document.getElementById('ethno').value;
var osev = window.document.getElementById('oversev');
var usev = window.document.getElementById('undersev');
var yhtn = window.document.getElementById('yhyp');
var nhtn = window.document.getElementById('nhyp');
u=yhtn.checked?"yes":"no";
v=osev.checked?"yes":"no";
w=eth;
x=size;
y=location;
z=ysah.checked?"yes":"no";
我很确定我错误地实现了附加变量 and/or 在此处错误地设置了 html 表单:
</select>
</p>
<label >Previous SAH?</label>
<input type="radio" name="prevsah" value="yessah" id="yessah"
onclick="getRisk()" />
Yes
<input type="radio" name="prevsah" value="nosah" id="nosah"
onclick="getRisk()" />
No
<p>
<label >Hypertension?</label>
<input type="radio" name="htn" value="yhyp" id="yhyp"
onclick="getRisk()" />
Yes
<input type="radio" name="htn" value="nhyp" id="nhyp"
onclick="getRisk()" />
No
<p>
<label >Age over 70?</label>
<input type="radio" name="oversev" value="osev" id="osev"
onclick="getRisk()" />
Yes
<input type="radio" name="oversev" value="usev" id="usev"
onclick="getRisk()" />
No
<br>
如有任何建议,我们将不胜感激。
祝福,
蒂姆
检查了您的损坏代码。它在控制台上给出错误。 Uncaught ReferenceError: Invalid left-hand side in assignment
。尝试使用 w=="jp"
而不是 w="jp"
来满足您的所有条件。
并替换以下
var osev = window.document.getElementById('oversev');
var usev = window.document.getElementById('undersev');
和
var osev = window.document.getElementById('osev');
var usev = window.document.getElementById('usev');
您使用的 ID 有误。