0
       $.getJSON('/CourtHouseManagement/LoadLawCourt/?cityId=' + id, function (result) {

                $('#JusticeCourtTable').html('');

                for (var i = 0; i < result.length; i++) {

                    var tablestring =

                        '<tr>' +
                        '<th>' + result[i].CourtID + '</th>' +



'<th><button type="button" class="btn btn-sm btn-primary" onclick="javascript:selectClaimant(' + result[i].CourtID + ',\'' + result[i].Name +');">Update</button></th>'+   //Problem HERE

'<th><button type="button" class="btn btn-sm btn-primary" onclick="javascript:selectClaimant(' + result[i].CourtID + ',\'' + result[i].Name +');">Delete</button></th>'  //Problem HERE


                    tablestring += '</tr>';
                    $("#JusticeCourtTable").append(tablestring);
                }
            });
        }
    }


    function selectClaimant(CourtID, Name) {  

        alert(CourtID + Name);


    }

I load datas to table.If **i click to "Delete" or "Update" button , ı want to send CourtID and Name for selected row.**I tried above code.When i click to "Update" or "Delete" button , i get below exception.

Uncaught SyntaxError: Unexpected number 

When i click to button "selectClaimant" function never works.Where i miss exaclty ? How can i send CourtID and Name on "Update" or "Delete" button click ?

Any help will be appreciated.

Thanks.

3
  • Can you post the data in the result array? Commented Jun 24, 2014 at 15:03
  • how come , do you need column names of datas ? Actually datas display withouy any problem.I just want to send selected row Id and name on button click Commented Jun 24, 2014 at 15:04
  • may anybody please help me about button click sneding parametsr thanks Commented Jun 24, 2014 at 15:07

1 Answer 1

1

Have you tried like this:

$.getJSON('/CourtHouseManagement/LoadLawCourt/?cityId=' + id, function (result) {
        $('#JusticeCourtTable').html('');
        for(var i = 0; i < result.length; i++){
            var tablestring ='<tr><th>'+result[i].CourtID + '</th>' +'<th>'+
            '<button type="button" class="btn btn-sm btn-primary" onclick="selectClaimant(\'' + result[i].CourtID + '\',\'' + result[i].Name +');">Update</button></th>'+
            '<th><button type="button" class="btn btn-sm btn-primary" onclick="selectClaimant(\'' + result[i].CourtID + '\',\'' + result[i].Name +');">Delete</button></th>'

            tablestring += '</tr>';
            $("#JusticeCourtTable").append(tablestring);
        }
    });

Also, it's possible to find the values this way:

  $.getJSON('/CourtHouseManagement/LoadLawCourt/?cityId=' + id, function (result) {
        $('#JusticeCourtTable').html('');
        for(var i = 0; i < result.length; i++){
            var tablestring ='<tr><th>'+result[i].CourtID + '</th>' +'<th>'+
            '<button type="button" class="btn btn-sm btn-primary" data-courtid="'+result[i].CourtID+'" data-name="'+result[i].Name+'">Update</button></th>'+
            '<th><button type="button" class="btn btn-sm btn-primary" data-courtid="'+result[i].CourtID+'" data-name="'+result[i].Name+'">Delete</button></th>'

            tablestring += '</tr>';
            $("#JusticeCourtTable").append(tablestring);
        }
    });

    $(document).on('click', '#JusticeCourtTable button', function(){
        alert($(this).data('courtid')+' - '+$(this).data('name'));
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.