I figured this out! Anyone who is curious, I placed the javascript variable in a different script, which resides within the loop where the php results are displayed.
Code:
<script>
var title = <?php echo json_encode($book_title); ?>;
</script>
I have also edited my answer above to show specifically where I placed this.
I have a problem I've been trying to work through, to which I think there is a probably a simple solution I am missing. I am trying to pass a variable from php to javascript. Seems like it should be easy. The php variable will echo all I want it to; it will echo to the php file where the code is written, and it will echo into the jquery window where my results are listed (from a google books search). But the value of the variable will not propagate...
Leave a comment: