In my table i have a column for a checkbox, when a user ticks that it should select all other check boxes underneath and if i click it again then the function deselect all the check boxes. I have also added drop down menu so if a user ticks a first box and selects add option then it should invoke some ajax method. This is what i have done:
var ajReq = new XMLHttpRequest();
$(document).ready(function () { Table();});
function Table(data) {
var DisplayTable = '<table><tr><th>Name</th><th>Name2</th><th><input type="checkbox" id="SelectCheckbox"/></th></tr>';
var counts= 0;
for (var getdata in data) {
var row = '<tr class=\'row\'select=\'' + data[getdata ].ID+ '\'</tr>';
counts+= '<td>' + data[getdata].Name+ '</td>';
counts+= '<td>' + data[getdata].Name2+ '</td>'
counts+= '<td><input type="checkbox" class="SomeAjaxMethod" methd-DoSomething= "' + data[getdata ].ID+'"></td>'
counts++;
DisplayTable += counts;
}
table += '</table></div>';
$('#DisplayTable').html(DisplayTable ); }
<div id="DisplayTable"></div>
$(function () {
$("#SelectCheckbox").click(function () {
$(".SomeAjaxMethod").attr('checked', this.checked);
});
$(".SomeAjaxMethod").click(function () {
if (this.checked == false) {
$("#SelectCheckbox").attr('checked', false);
}
});
});
When i add a Breakpoint to
#SelectCheckBox
it gets executed when a page is load, it should be executing after i selected a checkbox. I am also using drop down menu to perform some action, how do i attach check box to drop down menu, for example after selecting all the staff i want to delete them, i have already wrote SQL delete statment i just want to know how to i link check box with my drop down menu. this is my drop down menu:
<div class="dropdown">
<div class="btn-group">
<button type="button" id="id1" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Select...
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a class="Delete-staff">Attended Detention</a></li>
<li><a class="Edit-Staff">Letter Sent</a></li>
</ul>
</div>
</div>