Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have bind dynamic table in ASP.net with few controls in it like text box and radio buttons.
Also i have applied class property to respective controls, so that i can access them into the javascript.
By using Class property i can access textbox value in javascript but not able to check radio button is checked or not, as radio button is rendered in Span tag.
So can any one suggest me how can i check radio button is selected or not.

What I have tried:

I have tried below javascript, here i can access textbox value but anot able to check radio buttton is seleced or not.


JavaScript
$(document).ready(function () {
            $("#ContentPlaceHolder1_btnSubmit").click(function () {
                var Table = $("#ContentPlaceHolder1_DynamicTable").html();
                var Rows = $("#ContentPlaceHolder1_DynamicTable tr").length;
                var Col = 0;
                var ClientQuestionID = 0;
                var FeedbackID = "";
                var ClientQuestionId, OptionValue;
                $("#ContentPlaceHolder1_DynamicTable tr").each(function () {
                    var OptionID = $(this).find("input.HiddenOptionID").val();

                    if (OptionID == 1 || OptionID == 2) {
                        if (OptionID == 1) {
                            debugger;
                            ClientQuestionID = $(this).find("input.HiddenClientQuestionYESID").val();
                            FeedbackID = $(this).find("input.FeedbackYESValue").prop('checked', true);
                            alert(ClientQuestionID + "--->" + FeedbackID);
                        }
                        else if (OptionID == 2) {
                            debugger;
                            ClientQuestionID = $(this).find("input.HiddenClientQuestionNOID").val();
                            FeedbackID = $(this).find("input.FeedbackNOValue").val();
                            alert(ClientQuestionID + "--->" + FeedbackID);
                        }
                    }
                    else {
                        ClientQuestionID = $(this).find("input.HiddenClientQuestionID").val();
                        FeedbackID = $(this).find("input.FeedbackValue").val();
                        alert(ClientQuestionID + "--->" + FeedbackID);
                    }
                });
            });
        });
Posted
Updated 10-Jan-19 4:18am
v2
Comments
F-ES Sitecore 7-Jan-19 5:25am    
Post a relevant snippet of the html to show the structure.

1 solution

There are two ways you can check.

If you use a form:
First, consider that for a set of radio buttons (one doesn't make sense), they all are given the same name= , but can have different id= . They also, should each have a value= . When a button is checked, the data sent to the form (for that name'd group of radio buttons is that of the check item.

Locally, you may use the DOM and the id (which should be unique for every element on you page that has an id !). These have a checked property. You can test this value and determine which is checked.

Here's the DOM check for local usage:
var isChecked = document.getElementById(id).checked;




 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900