I have a html table, the first column is a list of checkboxes (as many as the table rows) all have id="checkbox1", "checkbox2", "checkbox3"
.... On the click of a button (id="modifyLink"
) I need to find the first checked checkbox (not bothered if there are any after the first) and then open my modal (id="modModal"
) and load a php page into it and post the value of the checked checkbox.
This is what I've come out with (obviously not working):
$function(){
$("#modifyLink").click(function(){
var checkbox = 'checkbox1';
for(var i=2; getElementById(checkbox).checked == 1; i++){
checkbox = 'checkbox'.i;
}
if(getElementById(checkbox)==true){
var id = getElementById(checkbox).val();
$(#modModal).modal('show');
$(#modModal).innerhtml = 'load my modal with index.php/trainings/mod passing the id variable possibly in POST';
});
};
If I'm going about this completely wrong can can someone suggest something completely different?
EDIT:
Ok I've studied in to this a bit more and gone for this:
$(function() {
$("#trainingRow").click(function() {
var id = $("#trainingRow").attr('data-value');
var dataString = 'id='+ id;
$.ajax({
type: "POST",
url: "/index.php/trainings/showDetail",
data: dataString,
dataType: 'json',
success: function(data) {
$("div#detailModal").html(data.html);
$("div#detailModal").modal('show');
}
});
return false;
});
});
but why doesn't the div#detailModal html update? I've checked what the php function returns through a var_dump and its exactly the HTML code i'm interested in but I don't know why it doesn't work (the returned variable is called html and i json_encode everything in php before I return it). A heads up would be nice, I think I've gone far with a bit of reading :)