更改事件出错.引用函数错误



我已经用计算逻辑创建了表格。我使用了onchange方法,但是我的函数中出现了引用错误。请帮助我找出我在哪里犯了错误或需要更改代码的地方。

我的功能 :

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>";

您得到的错误是TypeError: document.forms.MyForm.totalMrc is undefined 。这意味着表单中没有带有 id totalMrcinput

最新更新