Inside a form, I've a hidden field:
<input type="hidden" name="checkedData" id ="checkedData" />
Now, Inside on the page, I've a model which is fetching records in a data table . Say, I've selected 3 rows out of 5.
Now, I want to store these 3 ids into a variable and assign it to the above hidden field so as to fetch it on the controller. Please correct me where I'm wrong.
var data;
$.each($("input[name='checkbox']:checked"),
function () {
alert(this.value); // will print the id of all the selected checkboxes.
//I want the ids of all 3 checkboxes here in one variable seperated by comma.
//Something like this :
//data = 1,2,3; [not getting how to store "this.id" dynamically into one variable]
});
And then,
document.getElementById("checkedData").value = data;
And instead of var data, if I take an array, then, how to assign that array's value into the above hidden field. How to achieve this? Kindly suggest.