我嘗試更新的JavaScript計算器我在四年前做了一個神經外科醫生。它需要一些關於顱內動脈瘤的變量,並根據三項不同的隊列研究給出預計的破裂率。我正在嘗試使用相同的方法包含更多變量的新薈萃分析。不幸的是,當我添加新的變量,如果函數計算器打破....HTA:使用Javascript計算器 - 增加新的變量
原來的計算器是這樣的: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>
我已經添加了兩個新的是/否變量和一個額外的下拉式選擇(種族),指數地增加了可能的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";
我敢肯定,我錯誤地實施了額外的變量和/或錯誤地設置了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>
任何意見將不勝感激。
最良好的祝願,
添
新(碎)代碼:http://www.timkilleen.com/calc3.html – user2521705
原件(工作)代碼:http://www.timkilleen.com/calc1.html – user2521705
請[編輯],幷包括在問題的代碼(鏈接是好的,但其本身必須在問題體的代碼) –