 <p>I suggest you to create json object from your vars and pass it as argument, something like:</p> <pre><code>&lt;button id="modalBtn" type="button" onclick="ShowProduct(&lt;?php echo json_encode(array($title, $description, $img))?&gt;);"&gt; View Details &lt;/button&gt; </code></pre> <p>Or (for more readable keys)</p> <pre><code>&lt;button id="modalBtn" type="button" onclick="ShowProduct(&lt;?php echo json_encode(array('title' =&gt; $title, 'descr' =&gt; $description, 'img' =&gt; $img))?&gt;);"&gt; View Details &lt;/button&gt; </code></pre> <p>And your <code>ShowProduct</code> function you can define like:</p> <pre><code>function ShowProduct(params) { console.log( params ); // do other stuff } </code></pre> <p><strong>Update:</strong></p> <p>if your vars are already in array you can:</p> <pre><code>// pass this array: ShowProduct(&lt;?php echo json_encode($your_array)?&gt;) // fill new array with required keys only ShowProduct(&lt;?php echo json_encode(array($your_array['title'], $your_array['description'], $your_array['img']))?&gt;) </code></pre>