我正在尝试计算列表框上的值,但我的代码不起作用这是我的 javascript 代码:
var val=document.getElementById('inh').value;
var temp=val.split("");
function sum(){
var val = document.getElementById('inh').value;
var temp = val.split(" ");
var total = 0;
var v;
for(var i = 0; i < temp.length; i++) {
v = parseFloat(temp[i]);
if (!isNaN(v)) total += v;
}
document.getElementById('resultSum').innerHTML=total;
}
这是html代码:
<label for="ttotal"></label>
<input type="text" name="ttotal" id="ttotal" onkeyup="sum()" />
和
<select name="inh[<?php echo $no; ?>]">
<option value="">--Pilih--</option>
<option value="1" <?php if($datatampil['dosis_inh_perhari']==1) echo 'selected'; ?>>1 tablet</option>
<option value="2" <?php if($datatampil['dosis_inh_perhari']==2) echo 'selected'; ?>>2 tablet</option>
<option value="3" <?php if($datatampil['dosis_inh_perhari']==3) echo 'selected'; ?>>3 tablet</option>
</select>
谢谢