Having trouble retrieving the chosen option from the radio button list

I am struggling with a radiobutton list

 <asp:RadioButtonList CssClass="radioLable" ID="rbListPointsCat" runat="server"   RepeatDirection="Horizontal"
                    AutoPostBack="true" OnSelectedIndexChanged="rbListPointsCat_SelectedIndexChanged">
                    <asp:ListItem runat="server" Value="Yes" />
                    <asp:ListItem runat="server" Value="No" />
                </asp:RadioButtonList>

Here is the JavaScript function I am using

          function CheckValue(sender, args) {

        var rblist = document.getElementById('<% =rbListPointsCat.ClientID%>');
        for (var x = 0; x < rblist.cells.length; x++) {
            if (rblist.cells[x].checked) {
                var Choice = (rblist.cells[x].innerText);
                alert(Choice);
            }
        }


        if (Choice=="No") {
            if (txtRemarks.value == "") {
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
            }
        }
        else {
            args.IsValid = true;
        }
    }

However, I cannot seem to retrieve the checked value as it keeps showing up as undefined. Could someone please assist me in identifying where I may have made an error?

Answer №1

Give it a name,

      function IdentifyValue(sender, parameters) {

    var radioButtons = document.getElementsByTag('<% =rbRadioButtonOptions.ClientID%>');
    for (var index = 0; index < radioButtons.cells.length; index++) {
        if (radioButtons.cells[index].selected) {
            var Selection = (radioButtons.cells[index].textContent);
            alert(Selection);
        }
    }


    if (Selection=="Yes") {
        if (txtMessage.value == "") {
            parameters.ValidityCheck = false;
        }
        else {
            parameters.ValidityCheck = true;
        }
    }
    else {
        parameters.ValidityCheck = true;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can a C# Enum be made accessible to COM Interop callers?

I have a managed assembly that is accessed through COM Interop by clients such as VBScript and Perl. The classes in the assembly are decorated with attributes like [ClassInterface(ClassInterfaceType.AutoDual)], [GuidAttribute("ebc25cf6-9120-4283-b972-0e552 ...

XMLHTTP is not accessible in the Department of Health

My D.O.H framework is powered by nodejs, specifically version 1.10. While I understand that nodejs typically uses xmlhttprequest or other modules for XHR requests, in my scenario, I am opting to utilize Dojo's xhr instead. Unfortunately, it seems tha ...

Creating a Authentic Screw Top Appearance with CSS

I am striving to create a realistic screw head. Here is what I have done so far: <div class="screw"><div class="indent"></div></div> .screw { position: absolute; top: 10px; left: 49%; width: 30px; height: 30px ...

Retrieving a function from a JavaScript file located in a publicly accessible directory

Having trouble accessing a function from the JS file scripts.js within the public folder where my CSS file is also located. Despite following various tutorials like this, I keep encountering the error message Error: Cannot find module './scripts.js&ap ...

Sleek Dialog Boxes with Bootstrap 4 - Bootbox Modal

Within the structure of my webpage, there resides a table containing various elements. One specific cell within this table holds a link that triggers jQuery scripts upon being clicked. An example action initiated by clicking this link is displaying a Boots ...

What is the best way to pass a dynamically updated value to the controller?

<form id="participantsForGd"> <span id="GroupID"></span> //example: group id 2 will be displayed here <button id="GdStartTest">Start test</button> </form> I need to pass the value of GroupID to the controller through an ...

Having an issue where my meshes disappear when using the Unreal Bloom render pass in ThreeJS. Any ideas on what might be causing

Just starting out with Three and I'm really enjoying it, but I seem to be stuck on a problem. The code in this gist might help: https://gist.github.com/TheeBryanWhite/a7a2041fc8848a0ba449897883c43bdc Initially, the first render functions correctly b ...

triggers an unexpected error in console.log

I need help with the following code: function printName(obj) { console.log(obj.name); } printName({ name: "myName" }); (function displayError(errorMsg){ console.log(errorMsg); })("Error"); However, when I try to run this code, I am encountering a T ...

Error in React Router when using TypeScript

Encountering errors while trying to set up router with React and TypeScript. https://i.sstatic.net/muSZU.png I have already attempted to install npm install @types/history However, the issue persists. Your assistance would be greatly appreciated. Thank y ...

Displaying a div after a successful form submission using Jquery

I created two popup windows. One is used to ask the user whether they want to submit the form, and if they click 'yes', the form is submitted. The issue I encountered is that the other popup window should be shown after the form is successfully s ...

Diversifying collection of entities

Imagine having an array structured like this: [ { id: 1, name: "Foo", quantity: 2 }, { id: 2, name: "Bar", quantity: 3 }, ] The goal is to duplicate or expand the array elements based on the ...

Tips for incorporating SOS.DLL into my project

I am looking to enhance my Bug Finder open source project by incorporating support for .NET managed processes faults. Is there anyone who can help me figure out how to connect my application with the WinDBG SOS.DLL extension included in the .NET framework ...

When the page is loaded, populate FullCalendar with events from the model

On page load, I am attempting to populate events with different colors (red, yellow, green) on each day of the calendar. Here is a simple example showcasing events for three days: https://i.sstatic.net/YzJ4E.png I have data in a model that indicates the ...

Create a JavaScript file that will generate a map based on data from an SQL

I am currently working on developing a Leaflet map with numerous markers. To streamline the process of updating the map, I have stored all the markers in a MySQL database. A PHP script is utilized to retrieve the data from the database, format it in a way ...

Sort through the angular data using an array of identifiers

I am working with a json file that contains my data [{"id":"349","title":"event 1"},{"id":"350","title":"event 2"},{"id":"351","title":"event 3"}] Users have the ability to save events to local storage, which are then stored in an array $storage.myEven ...

Troubleshooting issues with Shadowbox and jQuery in a photo gallery

Starting with a bit of background, I must clarify that my knowledge of Javascript/jQuery is basic, and every new task is a valuable learning opportunity for me. The support from the Stack Overflow community has been incredibly beneficial throughout this jo ...

Issue with AngularJS for loop incorrectly incrementing when there is a single item in the array

Within my Angular application, there is a snippet of code that looks like this: for (var i = 0; i < $scope.itemList.length; i++) { if ($scope.itemList[i].serialNumber == quickCode) { console.log(i) returnsService.getNoReceiptErrorMe ...

Is there a Node Package available for storing data indefinitely?

When I execute my code, I need to store a variable permanently. Is there a node package or another method to achieve this? I want to ensure that I can access the stored data even after restarting my server. For instance, in my file named "runMe.js": var ...

Help provided for Infragistics XamFormulaEditor and FormulaEditorDialog in specific scenarios

Incorporating the formula editing functionality into my XamDataGrid control in our WPF application is proving to be a challenge. With the AutoGenerateFields property set to false, the data binding works seamlessly. An essential component is the XamFormulaE ...

Storing data with just a click

Upon clicking the link <a href="http://localhost/redmine/projects/'+ value.id+'">'+ value.name+'</a>, I aim to store the value.id into the following variable: x is the variable. var x = document.getElementById(value.id).va ...