Click here to Skip to main content
15,918,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
In my HTML table i want to get the checked value for each row in my table, but it keeps returning false even know that i am selecting it

What I have tried:

$(document)
.ready(function () {
 
    var myUrl = $("#myUrl").val();
    var arrayDetails = new Array();
    var row = 1;
 
    function NewEntry(area, process, value1, value2, value3, comment) {
 
        this.Area = area;
        this.Process = process;
        this.Value1 = value1;
        this.Value2 = value2;
        this.Value3 = value3;
        this.Comment = comment;
    }
 
// dropdown change
 
    $('#ProList').on('change', function () {
 
        var selectedValue = $('#ProList').val();
 
        $.ajax({
            type: "GET",
            url: myUrl1,
            contentType: "application/json; charset=utf-8",
            datatype: JSON,
            data: { 'proList': selectedValue },
            success: function (result) {
 
                $("#mainData").empty();
 
                $.each(JSON.parse(result), function (i, item) {
                    var row = i + 1;
 
                    $("#mainData").append(
                        "" +
                        "" + item.Process + "" +
                        "" + item.Checks + "" +
                        "" +
                        "<div class="btn-group" data-toggle="buttons" "="" +="">" +
                        "<label class="btn btn-success" "="" +="">" +
                        "<input type="radio" name="options1" id="green_" + row + "" "="" +="">" +
                        "<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
                        "</label>" +
 
                        "<label class="btn btn-warning" "="" +="">" +
                        "<input type="radio" name="options2" id="yellow_" + row + "" "="" +="">" +
                        "<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
                        "</label>" +
 
                        "<label class="btn btn-danger" "="" +="">" +
                        "<input type="radio" name="options3" id="red_" + row + "" "="" +="">" +
                        "<span class="glyphicon glyphicon-ok" "="" +=""></span>" +
                        "</label>" +
 
                        "" +
                        "<textarea id=" + " '"="" +="" "comments_"="" row="" "'"="" "type="text" placeholder="" class="form-control input-md"></td>" +
 
                        "</tr>");
                });
            },
            error: function () {
            }
        });
 
    });
 
// submit event
 
<pre>   $("#subButton").click(function () {
 
        var rowCount = $('#mainData >tr').length;
 
        for (var i = 1; i <= rowCount; i++)
        {
            var areaEntered = document.getElementById("process_" + i).innerText;
            var processEntered = document.getElementById("checks_" + i).innerText;
 
            var valueEntered1 = document.getElementById("green_" + i).checked;
            var valueEntered2 = document.getElementById("yellow_" + i).checked;
            var valueEntered3 = document.getElementById("red_" + i).checked;
 
            var commentEntered = document.getElementById("comments_" + i).value;
 
            var entry = new NewEntry(areaEntered, processEntered, valueEntered1, valueEntered2, valueEntered3, commentEntered);
 
            arrayDetails.push(entry);
        }
 
        sendToController();
    });
 
    function sendToController() {
        $.ajax({
            type: "POST",
            url: myUrl,
            contentType: "application/json; charset=utf-8",
            datatype: JSON,
            data: JSON.stringify({ methodParam: arrayDetails }),
            success: function () {
                alert(" Click Ok to return");
            },
            error: function () {
                alert(test);
            }
        });
    }
});</textarea></div>
Posted
Updated 7-Nov-17 0:59am
v3
Comments
Karthik_Mahalingam 3-Nov-17 6:12am    
post the markup code of the table
Member 11596389 3-Nov-17 6:17am    
i have added this below
Karthik_Mahalingam 3-Nov-17 6:26am    
try calling this code
$("#subButton").click(function () {
 
               var rowCount = $('#mainData >tr').length;
 
               for (var i = 1; i <= rowCount; i++)
               {
                   var areaEntered = document.getElementById("process_" + i).innerText;
                   var processEntered = document.getElementById("checks_" + i).innerText;
 
                   var valueEntered1 = document.getElementById("green_" + i).checked;
                   var valueEntered2 = document.getElementById("yellow_" + i).checked;
                   var valueEntered3 = document.getElementById("red_" + i).checked;
 
                   var commentEntered = document.getElementById("comments_" + i).value;
 
                   var entry = new NewEntry(areaEntered, processEntered, valueEntered1, valueEntered2, valueEntered3, commentEntered);
 
                   arrayDetails.push(entry);
               }
 
               sendToController();
           });

at the last line of success event in the ajax call.
Member 11596389 3-Nov-17 8:59am    
sure this is the same code??
Karthik_Mahalingam 3-Nov-17 9:02am    
run this code in the console window and see whether you are getting the value
document.getElementById("process_1").innerText;

1 solution

make the name property same to all the radio button to group it.
<input type=" radio" name="Colors" id="green_" + row + "" "=" " +=" ">"
     "<input type=" radio" name="Colors" id="yellow_" + row + "" "=" " +=" ">" +
     "<input type=" radio" name="Colors" id="red_" + row + "" "=" " +=" ">"
 
Share this answer
 

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