我创建了一个场景,我需要3个单选按钮来处理多个问题。我在单选按钮上添加了值,我想将所选单选按钮的总点数相加,并将其显示在文本框中。
这是我的代码,我在试图弄清楚为什么我收到未定义的错误消息时遇到了困难。
function getSelectionPoints(selection) {
return parseInt(selection.split(",")[1]);
}
function getSelectionObj(selectionID) {
var selection = null;
if(selectionID == 1)
selection = document.getElementById("<%=selection1.ClientID %>").getElementsByTagName("input");
else if (selectionID == 2)
selection = document.getElementById("<%=selection2.ClientID %>").getElementsByTagName("input");
else if (selectionID == 3)
selection = document.getElementById("<%=selection3.ClientID %>").getElementsByTagName("input");
return selection;
}
function getTotalPoints() {
var totalPoints = 0;
var selection;
var promotionDropdown = document.getElementById("<%=dropDownPromotionTo.ClientID %>");
var promotionFromID = parseInt(document.getElementById("<%=promotionIDFromHidden.ClientID %>").value);
var promotionToID = parseInt(promotionDropdown.options[promotionDropdown.selectedIndex].value);
for (var i = 1; i <= 9; i++) {
selection = getSelectionObj(i);
if (i == 9 && (promotionFromID == 2 || promotionFromID == 3 || promotionToID == 2 || promotionToID == 3)) {
totalPoints += 0;
}
else if (selection != null) {
for (var j = 0; j < selection.length; j++) {
if (selection[j].checked) {
totalPoints += getSelectionPoints(selection[j].value);
break;
}
}
}
}
alert(totalpoints);
return totalPoints;
}
<asp:RadioButtonList ID="selection1" runat="server"
EnableTheming="True" SkinID="Black" CausesValidation="True" onchange="updateMyPoints(false, true);">
<asp:ListItem Value="1,6">Spectacular</asp:ListItem>
<asp:ListItem Value="2,4" Selected="True">Average</asp:ListItem>
<asp:ListItem Value="3,0">Needs improvement</asp:ListItem>
</asp:RadioButtonList>
答案 0 :(得分:4)
JavaScript区分大小写,请使用totalPoints
代替totalpoints
:
alert(totalPoints);