Pass a PHP variable into JavaScript
Say you need a variable from your PHP code to be used in your JavaScript. A really quick way to do this is to do something like this:
<script type="text/javascript">
var dbElements = "<? echo $dbTotal?>";
</script>
$dbTotal is my PHP variable that is holding the total number of rows in a DataBase. dbElements now contains this value and can be used in my javascript for looping purposes!
<script type="text/javascript">
var dbElements = "<? echo $dbTotal?>";
</script>
$dbTotal is my PHP variable that is holding the total number of rows in a DataBase. dbElements now contains this value and can be used in my javascript for looping purposes!
0 Comments:
Post a Comment
<< Home