-1

I have a JavaScript function for scrolling of table when button is click but I have multiple tables in my code and cant use multiple function for each table I want to store the id's of all table in dynamic way using PHP.

<script type="text/javascript">
    // Do something in JavaScript
    var x = <?php echo $row_[document_id]; ?>;
    // etc..
</script>

document_id is were value are accessed dynamically in PHP.

PrakashG
  • 1,642
  • 5
  • 20
  • 30
AKG
  • 1
  • 1
  • 1
    PHP is executed server-side and then the page is rendered client-side – Cid Jun 14 '19 at 08:07
  • take a look at `ajax()`. Once you get the hang of it I believe your question should be answered – Red Bottle Jun 14 '19 at 08:07
  • 2
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Cid Jun 14 '19 at 08:11

2 Answers2

0

Instead of using

var x = <?php echo $row_[document_id]; ?>;

you can use something like this:

<?php

echo '<script>var x = ' . $row_document_id . ';</script>';

?>

If data is a string, you can use double quotes:

<?php
echo '<script>var x = "' . $row_document_id . '";</script>';
?>

Also it is preferred to use let instead of var.

Hope that helped.

Coder Amogh
  • 145
  • 1
  • 10
0

Save the PHP variable value in HTML hidden input element.

    <input type="hidden" value="<?php echo $row_[document_id]?>" id="getValue">

And then get the value from JavaScript or jQuery.

    var x = $("#getValue").val();