Jump to content

how to pass a php variable in js file


phpmady

Recommended Posts

Hi,

 

 

this is my js file, and i am in need of php variable passing to the js file

 

$(document).ready(function() {
$('div.menu_list').cluetip(
{
  width:570,
  cluetipClass: 'jtip', 
  arrows: true, 
  dropShadow: false,
  hoverIntent: true,
  sticky: true,
  positionBy:       'mm',
  hoverClass:       'highlight',
  mouseOutClose: true,
  closePosition: 'title',
  leftOffset: 0,
  closeText: '<img src="plug/cluetip/stop_win.png" alt="close" />'
});

  
});

 

I want to make a dir path in above line:

 

 

closeText: '<img src="_DIR_plug/cluetip/stop_win.png" alt="close" />'

 

 

 

Hope you guys help me to solve

Thanks

Link to comment
https://forums.phpfreaks.com/topic/204286-how-to-pass-a-php-variable-in-js-file/
Share on other sites

As Neil suggests change the somefile.js to somefile.php and include the necessary code to define and write the _DIR_ value into the file. Of course you need to change any of the files that call the js file to point to the new file name:

 

<?php

// Insert code to define _DIR_

?>
$(document).ready(function() {
$('div.menu_list').cluetip(
{
  width:570,
  cluetipClass: 'jtip', 
  arrows: true, 
  dropShadow: false,
  hoverIntent: true,
  sticky: true,
  positionBy:       'mm',
  hoverClass:       'highlight',
  mouseOutClose: true,
  closePosition: 'title',
  leftOffset: 0,
  closeText: '<img src="<?php echo _DIR_; ?>plug/cluetip/stop_win.png" alt="close" />'
});

As Neil suggests change the somefile.js to somefile.php and include the necessary code to define and write the _DIR_ value into the file. Of course you need to change any of the files that call the js file to point to the new file name:

 

<?php

// Insert code to define _DIR_

?>
$(document).ready(function() {
$('div.menu_list').cluetip(
{
  width:570,
  cluetipClass: 'jtip', 
  arrows: true, 
  dropShadow: false,
  hoverIntent: true,
  sticky: true,
  positionBy:       'mm',
  hoverClass:       'highlight',
  mouseOutClose: true,
  closePosition: 'title',
  leftOffset: 0,
  closeText: '<img src="<?php echo _DIR_; ?>plug/cluetip/stop_win.png" alt="close" />'
});

 

thank You mjdamato

 

As you said i use the REQUEST_URI method to get the root directory

 

Thanks

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.