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); ?>
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); ?>
Share
Improve this question
edited Sep 22, 2014 at 13:58
CMS
7063 gold badges9 silver badges34 bronze badges
asked Sep 22, 2014 at 12:41
gatusogatuso
812 gold badges2 silver badges8 bronze badges
7
- You can't do that. But you can alert or console.log(get_parestotal) – andrex Commented Sep 22, 2014 at 12:43
- 1 the echo is in PHP server side, while the variable is on the client side... – fast Commented Sep 22, 2014 at 12:43
- Right. Can you linking me some example using the console.log ? thanks – gatuso Commented Sep 22, 2014 at 12:44
- developer.chrome./devtools/docs/console – Alex K. 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. – epascarello Commented Sep 22, 2014 at 12:47
3 Answers
Reset to default 7You 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();
You can either do alert(myvar) or console.log(myvar).
Caveat: console.log is only supported in certain browsers...see the link.
if you want a console output than use console.log(get_parestotal);