Client scripts and server code cannot be mixed this way. Javascript only runs on the browser and the only way it can communicate with your backend script is via AJAX (or some other network) calls.

Instead, have your server render out the HTML for the tabs with the names, as well as the tab panes with their respective content, then have your script find those tabs (based on the data attributes) and turn them into dynamic navigation. This will be better for SEO since even if javascript is disabled, your site content is still visible.