colombian Posted September 12, 2007 Share Posted September 12, 2007 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.] Link to comment https://forums.phpfreaks.com/topic/69056-php-variables-inside-external-javascript-file-workaround/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.