1

Html and php:

<?php $a = 1380; ?>
    <script>
<?php $b = document.write(month); ?>
    </script>
<div id="firstshow">

    <div id="test1">
       <div class="col-xs-5 text-right">
       <b><?php echo $a/$b; ?> &euro;/month</b><!-- the result I wish to divide $a from $b -->
       </div>
    </div>

    <div class="dropdown">
       <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"><b class="pull-left">36</b>per month
       <i class="fa fa-chevron-down pull-right" aria-hidden="true"></i></button>
       <ul class="dropdown-menu">
          <li><a href="#">12</a></li>
          <li><a href="#">24</a></li>
          <li><a href="#">36</a></li>
       </ul>
    </div>

</div>

Below of all div is the script of this (below) jQuery.

jQuery

$("#firstshow .dropdown-menu li a").click(function(){   
    var month = $('#firstshow button b').text($(this).text());   
});

I am trying to combine a dynamic variable $a in php with the variable month as a result of jquery and divide the two them.

Morteza QorbanAlizade
  • 1,520
  • 2
  • 19
  • 35
Vasilis Greece
  • 861
  • 1
  • 18
  • 38
  • 1
    What do you expect from this line `` ? – Dekel Oct 16 '16 at 10:55
  • In this case the result is 36; – Vasilis Greece Oct 16 '16 at 10:56
  • Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – u_mulder Oct 16 '16 at 10:56
  • but `document.write` is javascript code, and you try to use it inside `php` block code... – Dekel Oct 16 '16 at 10:56
  • No, PHP is server site language and js is browser site. When execute js in browser in that time there is no php exist. Because php send output into browser many time ago when js still working. What do you want to do? describe properly. – AHJeebon Oct 16 '16 at 10:58
  • Yes I know I dont know how to fetch the "month" variable in jquery and put it to variable $b in Php. That's is the main problem. – Vasilis Greece Oct 16 '16 at 10:58
  • In this link http://stackoverflow.com/questions/40063692/jquery-replace-text-without-erasing-the-list/40063769#40063769 I have a snippet I need to divide the variable $a (php) from variable month jquery. – Vasilis Greece Oct 16 '16 at 11:00
  • 1
    I see you posted an answer, but for reference in the future: if you want the value from PHP as a variable in javascript, you could do: ``, or you can add it to a `data-` attribute and retrieve it: `

    Other display HTML

    ` --- retrieve it with `var myData = $('#someDiv').data('myData');`
    – Chris Baker Oct 16 '16 at 16:43

1 Answers1

0

Ok I found the solution. In the end of divs I add a script

<script type="text/javascript">
    jQuery(document).ready(function($){
        $("#firstshow .dropdown-menu li a").click(function(){

         $('#test1 .col-xs-5 span').text(<?php echo $a; ?> / ($(this).text()));

    });
      });
</script>

and change the Html:

<div id="test1">
 <div class="col-xs-7">
    <span>1.459&euro;</span> <b>1.380 &euro;</b>
 </div>
 <div class="col-xs-5 text-right">
    <b><span>36</span> &euro;/month</b>     
 </div>
</div>
Vasilis Greece
  • 861
  • 1
  • 18
  • 38