3
<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?

1
  • Please elaborate more clear what your problem is. Commented Sep 15, 2017 at 19:33

1 Answer 1

6

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);  
});
Sign up to request clarification or add additional context in comments.

1 Comment

@shivzuh I'm assuming you're using Bootstrap. jsbin.com/kutocaqixo/edit?html,js,console,output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.