timwashere
timwashere

Reputation: 39

pass data to modal using javascript

I am creating a website in MVC5 using bootstrap with the boostrap tables library http://wenzhixin.net.cn/p/bootstrap-table/docs/index.html using:

$('#subscriber-table').on("click-row.bs.table", function (e, row, $element) {
                        console.log(row.SubscriberID);
                        $('#subscriberDialog').modal();
                    });

I receive the click on one of the table's records. This works great ony now I want to pass the json object called row to my created modal, so I can set the name input field. Like this:

$('#subscriberDialog').on('show.bs.modal', function (event) {

     $('#namefield').val('toSetName');
});

I have been trying to figure this out but I cant seem to get it to work.

Upvotes: 0

Views: 941

Answers (2)

Neeraj Verma
Neeraj Verma

Reputation: 495

What you can do you can set any custom attribute in modal to get the value.

like this :

$('#subscriber-table').on("click-row.bs.table", function (e, row, $element) {
  console.log(row.SubscriberID);
  $('#subscriberDialog').attr('data-custom-value', 'toSetName');
  $('#subscriberDialog').modal();
});


$('#subscriberDialog').on('show.bs.modal', function (event) {
     var val = $(this).attr('data-custom-value');
     $('#namefield').val(val);
});

Upvotes: 2

Zalak Thakrar
Zalak Thakrar

Reputation: 1

Pass Through array also like OnClick(['a','b','c']);

and Retrieve Like function checkData(value) { alert(value[0] + " " + value[2] .....); }

Upvotes: 0

Related Questions