我有一个表格。用户将填写它,并且在该表单的底部,我试图显示插入到表单页面中的基于值的值。
到目前为止,我根本没有得到任何输出,这是我的尝试:
HTML表格:
<form id="myform">
<select
name="sv_313"
onchange="calculate()"
id="sv_313"
>
<option value="Select One">Select One</option>
<option value="0.1">A</option>
<option value="0.2">B</option>
<option value="0.3">C</option>
</select>
<br/>
<input
type="number"
name="sv_312"
size="10"
maxlength="10"
onblur="calculate()"
id="sv_312"
/>
Calculated value
<div id="coverage"> </div>
</form>
的JavaScript:
<script>
//define an array for the possible values input via select menu
var spv = new Array();
spv["A"]=0.1;
spv["B"]=0.2;
spv["C"]=0.3;
//function to get the value from select menu
function getSAMprevalence()
{
var SAMprevalence=0;
var theForm = document.forms["myform"];
var selectedSAMprevalence = theForm.elements["sv_313"];
SAMprevalence = spv[selectedSAMprevalence.value]
return SAMprevalence;
}
//function to get the value from input field
function getInputvalue()
{
var Inputvalue=0;
var theForm = document.forms["myform"];
var Inputvalue = theForm.elements["sv_312"];
return Inputvalue;
}
//function to calculate using these two functions, and output into div named coverage:
function calculate()
{
var treatmentCoverage = getSAMprevalence() + getInputvalue();
document.getElementById('coverage').innerHTML =
""+treatmentCoverage;
}
</script>
我真的没有使用 javacsript 或任何东西的经验,任何指针都会非常感激。谢谢!
编辑:这是一个 jsfiddle,它设置在其中,说明缺少任何输出:( http://jsfiddle.net/rHu8J/3/