Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass php variable to javascript function
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3306314/how-to-pass-a-php-variable-to-javascript">How to pass a PHP variable to Javascript?</a> </p> </blockquote> <p>I need to somehow make this function to accept parameter.</p> <h3>index.html</h3> <pre><code>function dataOut(name2) { var names = name2.value; document.getElementById("output2").innerHTML = names; //even document.getElementById("output2").innerHTML= "blablabla"; //just to show that it works } </code></pre> <p>And the function will be called from :</p> <p>dbase.php</p> <pre><code>... echo "&lt;td&gt;&lt;a href='javascript:dataOut(this.value)'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; ... </code></pre> <p>I dont have problem on displaying the the table. The link does show with their respective "$row['FirstName']" which are string from database. I tried to use non-parameter function:</p> <pre><code>function dataOut(){} echo "&lt;td&gt;&lt;a href='javascript:dataOut()'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; </code></pre> <p>and these work fine.</p> <p>If i try to pass parameter, the function will not do anything; not even if i just want to print random string as in the commented section of the function. If i hover my mouse on the link created within that table i see:</p> <pre><code>javascript:dataOut(firstname) //where first name is the value of the $row['FirstName'] </code></pre> <p>Alternatives that i tried:</p> <pre><code>echo "&lt;td&gt;&lt;a href='javascript:dataOut(this.value)'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;a href='javascript:dataOut($row['FirstName'])'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; echo "&lt;td&gt;&lt;a href='javascript:dataOut('" . $row['FirstName'] .'")'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; //this give me undefined variable error echo "&lt;td&gt;&lt;a href='javascript:dataOut(". $row['FirstName']. ")'&gt;" . $row['FirstName'] . "&lt;/a&gt;&lt;/td&gt;"; // this no error </code></pre> <p>Any help would be appreciated. More over i tried also <code>&lt;a onclick=dataOut ....&gt;</code> which doesnt work either.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload