Fetch data from database and send it to javascript function
<p>I am selecting input values from the database and I want to send it to the javascript function <code>addVal()</code> so that I can retrieve this value. I do not want to use <code>echo</code>. It is not working right now and I don't know how I can make it work.</p>

<pre><code>&lt;h1&gt;trial,&lt;/h1&gt;
 &lt;div id ="val"&gt;   &lt;/div&gt;
  &lt;?php
 $name = $_POST['postname'];

$host = 'localhost';
$user = 'root';
$pass = 'root';
$db_name="big";



$conn = new mysqli($host, $user, $pass, $db_name);


if ($conn-&gt;connect_error) {
    die("Connection failed: " . $conn-&gt;connect_error);
} 
echo "connected";
$sql = "SELECT input FROM trial_db";
$result = $conn-&gt;query($sql);

if ($result-&gt;num_rows &gt; 0) {
    while( $row = $result-&gt;fetch_assoc()) {
        $value = $row['input'];
        addVal ($value);
    }

}
?&gt;

&lt;script&gt;
    function addVal (value){
        document.getElementById("val").innerHTML+= value ;
    }
&lt;/script&gt;
</code></pre>