我用计算逻辑创建了表。我使用了onchange方法,但是我的函数中有一个ReferenceError。请帮我找出我弄错的地方或我需要更改代码的位置。
我的功能:
function calculates()
{
var a = document.forms["MyForm"]["basicSeat"].value;
var b = a * document.forms["MyForm"]["basicSeatMrc"].value;
document.forms["MyForm"]["basicSeatMrcTotal"].value = b;
var c = document.forms["MyForm"]["crsSeat"].value;
var d = c * document.forms["MyForm"]["crsSeatMrc"].value;
document.forms["MyForm"]["crsSeatMrcTotal"].value = d;
document.forms["MyForm"]["totalMrc"].value = document.forms["MyForm"]["basicSeatMrcTotal"].value + document.forms["MyForm"]["crsSeatMrcTotal"].value;
}
My Table Code :
html = "<form name='MyForm'><table class='addrtable' border ='1' cellpadding='2' cellspacing='2'>";
html += "<tr><td valign='top'>";
html += "<tr bgcolor='#CCFFCC'><b><td>Seat Type</td><td>Quantity</td><td>MRC</td><td>NRC</td><td>Ext. MRC</td><td>Ext. NRC</td><b></tr>";
html += "<tr><td>Basic Seats</td><td><input type='text' id='basicSeat' name='basicSeat' onchange='javascript:calculates();' /></td><td><input type='text' id='basicSeatMrc' name='basicSeatMrc' value='17.00'/></td><td><input type='text' id='basicSeatNrc' name='basicSeatNrc' value='59.00'/></td><td><input type='text' id='basicSeatMrcTotal' name='basicSeatMrcTotal' value='0.00'/></td><td><input type='text' id='basicSeatNrcTotal' name='basicSeatNrcTotal' value='0.00'/></td></tr>";
html += "<tr><td>Conference Room Seats</td><td><input type='text' id='crsSeat' name='crsSeat' onchange='javascript:calculates();' /></td><td><input type='text' id='crsSeatMrc' name='crsSeatMrc' value='22.00'/></td><td><input type='text' id='crsSeatNrc' name='crsSeatNrc' value='59.00'/></td><td><input type='text' id='crsSeatMrcTotal' name='crsSeatMrcTotal' value='0.00'/></td><td><input type='text' id='crsSeatTrcTotal' name='crsSeatTrcTotal' value='0.00'/></td></tr>";
html+="</tr></table></form>";
答案 0 :(得分:0)
您获得的错误是TypeError: document.forms.MyForm.totalMrc is undefined
。这意味着您的表单中没有input
ID totalMrc
。