I am populating an element with some html: table, checkboxes. I have an onclick event in my checkbox, but the page doesn't seem to be listening to the click event. I suspect it's because it was loaded after the javascript checkall() function got put into the DOM.
Here's what I have:
<select name="showcuslist" id="showcuslist">
<option value="0">select a customer</option>
<option value="1">John Smith</option>
<option value="2">Jane Smith</option>
</select>
<div id="loadtables">---ajax loads stuff into here---</div>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#showcuslist").change(function(){
$.ajax({
data:"formId=grabcusinfo&cusid="+$(this).val(),
success:function(response){ eval(response); }
});
});
});
function checkall(){
$(".checkboxes").attr("checked",true);
}
</script>
Simply, when I get to this page I can select a customer from the dropdown menu. Nothing too complicated.
Jquery then calls a page on the server for the purpose of grabbing some info about that customer.
The info is actually a list of Notes, so nothing huge. But I format the notes into an html table.
The first column in that html table has checkboxes, corresponding to each Note record. I also put a Master Checkbox in the top, so if I check that box, all boxes will be checked.
The html table loads fabulously, however, that master checkbox isn't working.
Here's the html table I load into the
<?php
$alltables='<table>';
$alltables.='<tr>';
$alltables.='<th><input type="checkbox" id="checkall" class="checkall" onclick="checkall();" /></th>';
$alltables.='<th>Notes Title</th>';
$alltables.='</tr>';
$alltables.='<tr>';
$alltables.='<td><input type="checkbox" id="someID" class="checkall" /></td>';
$alltables.='<td>Notes Title Text...</td>';
$alltables.='</tr>';
$alltables.='</table>';
$("#loadtables").html("'.addslashes($alltables).'");
?>
The checkall(); function works fine if I load the table when the page loads, but not when I load a new table with new data.
I've been told this is where live() or bind() helps out, but I'm honestly not understanding the jquery docs.