Click here to Skip to main content
15,911,786 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am working on drupal for few weeks and I can't find a solution for this problem.

I made a variable_set($name,$value) in a form. The form is a checkbox and is used to activate or desactivate a slideshow. I have a js variable called active and I want to put the value of variable_get($name) in it. Here is my js code:
JavaScript
(function($) {
  $(document).ready(function(){
      var slidePause = 7000;
      var active = 0;

      if (active == 0){
        $('#big-slider').bxSlider({
         auto: true,
         controls: false,
         autoDirection: 'prev',
         autoStart:true,
         pause: slidePause
        });
        $('#little-slider').bxSlider({
         displaySlideQty: 3,
         moveSlideQty: 1,
         auto: true,
         controls: false,
         autoStart:true,
         pause: slidePause
        });
      }
      else { 
      $('#big-slider').bxSlider({
         auto: true,
         controls: false,
         autoDirection: 'prev',
         autoStart:false,
         pause: slidePause
        });
        $('#little-slider').bxSlider({
         displaySlideQty: 3,
         moveSlideQty: 1,
         auto: true,
         controls: false,
         autoStart:false,
         pause: slidePause
        });
      }
  });
}(jQuery));
Posted

JavaScript
var active = <?php echo variable_get($name); ?>;
 
Share this answer
 
v2
Comments
stephane1301 30-Jun-14 8:18am    
Thx but I already tried this and I test by doing this : alert(active); the value of active is and not 0 or 1..
Kornfeld Eliyahu Peter 30-Jun-14 9:30am    
Debug your PHP code - check what variable_get($name) returns to you...
stephane1301 1-Jul-14 0:24am    
The variable_get returns the result I want but I want to find a way to get it in my js file
Kornfeld Eliyahu Peter 1-Jul-14 1:09am    
This is the way - insert a PHP echo of the variable in to your JavaScript code...It works for thousands outthere, so if it does not for you it may be a problem with your code...Please share the relevant code so we can examine...
stephane1301 4-Jul-14 7:36am    
I know it work for others. this is why I did not understand. But my problem was solved by the drupal.setting thing. Thanks anyway
I found the solution. In my php file I put this:

drupal_add_js(array('active_slide' => array('var' => $var)), array('type' => 'setting'));

And I get the value in my js with this:

Drupal.settings.active_slide.var;

Thx to Kornfeld Eliyahu Peter for trying to help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900