I'm looking for a method to populate a div
with content based on which i click.
First of all, I generate a dynamic table like this:
user name total hours worked button(unique id, that i fetch from database)
user name total hours worked button(unique id, that i fetch from database)
user name total hours worked button(unique id, that i fetch from database)
The info i get is from database, and as for the buttons each one have a different id, the one from the database table, that corresponds to the user.
What i want to do now:
When I click detailed info, to go to another table, and for the user i clicked to make another table, with detailed data. I managed to make the function:
public function show_detailed_activity(){
$string = $this -> detailed_activity(2);
$string = str_replace("
", '', $string);
$function = "
$('#detailed_table').append('".$string."');
";
$empty = "$('#detailed_table').empty();";
$this -> javascript -> click('.btn.btn-info',$empty);
$this -> javascript -> click('.btn.btn-info',$function);
$this -> javascript -> compile();
}
detailed_activity is a function that gives me the string that in html is a table with the data i need, for the user with id that i pass.
But as you can see i just passed '2' to test if it work. So dosen't matter what button with class '.btn.btn-info', I click, my div will have the info of user with id '2'.
How can I make that, when i click button, first to retrieve the id of button, after to call the function that belongs to a Codeigniter model
and after to pass it to the div ?
Add an argument to your function.
public function show_detailed_activity(id){
$string = $this -> detailed_activity(id);
// ...
}
And call it like this, from within click event:
show_detailed_activity($(this).attr("id"));
As per your html you are assigning different classes so you can get all of them like
$('.tg tr th')
then if you want a particular one you can do something like this(assuming id the id are available through js)
$('.tg tr').find('#1')
html I used for this is
<table class="tg"><thead><tr><th class="tg-031e">Date</th><th class="tg-031e" id="1">Number of hours worked this day</th></tr></thead></table>
Hope this helps