1

I want to use bootstrap tabs dynamically but I can't figure out how. I basically need to get the name/id of the current tab and pass it into a PHP variable to then use in mysql WHERE clause to determine what data to show for that tab.

I can see this on the Bootstrap documentation -

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
e.target // newly activated tab
e.relatedTarget // previous active tab
})

BUT it really doesn't help me much with my actual code.

My code works like so ->

  • I get the tab titles from a SELECT query and a PHP while loop
  • I then use a different SELECT query with a WHERE clause that I need to be like -

    WHERE tab= $currenttab
    

    to generate the info to be shown for each tab in a PHP while loop

**UPDATE - i've realised that what I need to know is how to use ajax with the above piece of code from bootstrap to POST a jquery variable to a php variable ?? **

bb25
  • 55
  • 1
  • 8
  • Show your effort to implement `$.post`. – mickmackusa Jan 24 '20 at 09:19
  • I currently have this - `$(document).ready(function(){ $('a[data-toggle="tab"]').on('shown.bs.tab', function(e) { var x = $(e.target).text(); console.log(x); $.ajax({ type: 'post', url:'contacts_1.php', data:{'activeTab' : x}, success:function(result){ $('body').html(result); } ` }); }); });` – bb25 Jan 24 '20 at 09:23
  • I can now get the clicked on tab printed to a post varable - `` However, it is only printing the first tab clicked on after the page is refreshed. Meaning I have to manually refresh the page and click a new tab for it's ID to be posted. – bb25 Jan 24 '20 at 09:23
  • Please read the duplicate, then try some more, then edit your question to show your best attempt (please don't write question details as comments). – mickmackusa Jan 24 '20 at 09:24
  • If you no longer need support, you are authorized to retract your question. – mickmackusa Jan 24 '20 at 09:25
  • I have read the duplicate but it doesn't help me with my specific problem. – bb25 Jan 24 '20 at 09:26
  • It seems your question has fundamentally changed. Perhaps scrap this one and ask a new, fresh, minimal question – mickmackusa Jan 24 '20 at 09:29

0 Answers0