Sou Yang
Sou Yang

Reputation: 111

Why is this Undefined and how do i fix this? C#

I'm creating a scenario where I need 3 radio buttons for multiple questions. I added values to the radio button and I want to add up the total points of the selected radio button and display it into a text box.

Here's is my code and I'm having difficulties with trying to figure out why I'm getting an undefined error message. enter image description here

 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>

Upvotes: 0

Views: 215

Answers (1)

dotnetom
dotnetom

Reputation: 24901

JavaScript is case sensitive, use totalPoints instead of totalpoints:

alert(totalPoints); 

Upvotes: 4

Related Questions