Reputation: 135
<div class="btn-group m-b-5">
<button type="button" data-toggle="dropdown" class="btn dropdown-toggle btn-info">
Ana Kategori
<span class="caret"></span>
</button>
<ul role="menu" class="dropdown-menu">
<?php
while ($row = mysqli_fetch_assoc($resultDataTableTwo)){
echo '<li><a onclick="myFunction()">'.$row['Ana_Kategori'].'</a></li>';
echo ' <li class="divider"></li>';
}
?>
</ul>
</div>
so in order to call myFunction()
with the clicked dropdown items name, achieved by $row['Ana_Kategori']
, how may I proceed?
Upvotes: 3
Views: 756
Reputation: 5041
This is probably not what you actually want, but try it and let me know what you get.
change
echo '<li><a onclick="myFunction()">'.$row['Ana_Kategori'].'</a></li>';
to
echo '<li><a class="dropdown-link">'.$row['Ana_Kategori'].'</a></li>';
and then add this JS function
$(document).on('click','.dropdown-link',function(event){
event.preventDefault();
var $this = $(this);
var name = $this.text();
console.log("I clicked " + name);
});
Upvotes: 6