6

What is the best way to echo the variable get_parestotal?

Some help please! Thank you

  <script type="text/javascript">
 $(document).ready(function(){
                    var get_parestotal = 0
                $(".parestotal").each(function(){
                    get_parestotal += parseFloat($(this).text());
                });
                alert(get_parestotal);

            });

</script>



<? echo json_encode($get_parestotal); ?>
7
  • You can't do that. But you can alert or console.log(get_parestotal) Commented Sep 22, 2014 at 12:43
  • 1
    the echo is in PHP server side, while the variable is on the client side... Commented Sep 22, 2014 at 12:43
  • Right. Can you linking me some example using the console.log ? thanks Commented Sep 22, 2014 at 12:44
  • developer.chrome.com/devtools/docs/console Commented Sep 22, 2014 at 12:47
  • You want to output the info to the page? Than console.log is not what you want. Learn about innerHTML or appendChild. Commented Sep 22, 2014 at 12:47

3 Answers 3

7

You can log variables and so on in the console.

e.g.:

console.log(get_parestotal);

You can even concatenate witht he use of + console.log('This is your variable'+get_parestotal)

You can even add styling to your log (color, background-color,...):

console.log('%cThis is your variable'+get_parestotal+'!','color:green;');

There are some alternatives to console.log() you could use:

 console.warn();
 console.info();
 console.error();
 console.debug();
Sign up to request clarification or add additional context in comments.

2 Comments

You can also just use multiple arguments, ie console.log('bla', window, 123), if you use a good browser you can work with the output much better than as a string puu.sh/bJgmN/13103a5940.png
Thanks guys I not properly explained the problem above. I need to display the value on a div.
0

You can either do alert(myvar) or console.log(myvar).

Caveat: console.log is only supported in certain browsers...see the link.

Comments

0

if you want a console output than use console.log(get_parestotal);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.