Jump to content

PHP variables inside external JavaScript file (workaround?)


colombian

Recommended Posts

I have been trying to really separate JavaScript from HTML/PHP, just like with CSS.

My problem, is that I am having problems passing a PHP variable or making use of it through an external JS file.

 

If I was using inline JS I could pass it like:

<a href="bla.php" onclick=return confirm("Delete this item: <?php echo $item ?>")> Delete (works) </a>

 

However, using similar code in an external JS file, simply passes through as text.

Is there any way to accomplish something similar?

 

The new code is much nicer:

<a href="bla.php" class="delete"> Delete (doesn't quite work) </a> 

 

IS there a way to keep code this clean and properly separate the JS from the HTML while at the same time keeping the PHP $variable working?

 

I am well aware that JS runs on the client, and PHP on the server, I am just hoping to somehow pass this variable through some work around, if not I will keep using the inline version.

 

Thank you.

 

[Moderators: Please don't move this to the JavaScript section, it is mainly on topic for PHP and nobody checks those areas - thank you.]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.