Note that there are some explanatory texts on larger screens.

plurals
  1. POcall javascript function in php and pass php variables?
    primarykey
    data
    text
    <p>Say I have 3 variables, id, name, number, on a php script, $name, $number, $id</p> <p>On the PHP, I create a button</p> <pre><code> print "&lt;td&gt;&lt;form&gt;&lt;input type='button' name='edit' id='edit' onclick=ed($name, $number, $id) value='Edit' /&gt;&lt;/td&gt;"; </code></pre> <p>I want those 3 variables sent to my javascript.</p> <p>The function call seems to work just fine if I use</p> <pre><code>onclick=ed(this.id) </code></pre> <p>and modify the function header, and this passes the string "edit" but that's not quite useful.</p> <p>function header in javascript is</p> <pre><code>function ed(name, number, id) { //stuff here } </code></pre> <p>For whatever it's worth using this code gets me an error on the html, something about an unexpected } on line2 of the html document.</p> <p>Edit:I should clarify I said that code gives me errors so someone didn't just say "Well use this!" when I already expected it not to work.</p> <p>Using this:</p> <pre><code>&lt;input type='button' id='$id' onclick=ed(this.id) value='Edit' /&gt; </code></pre> <p>Allows me to send the value in $id to the javascript function because it was saved in the id field. Something along those lines is what I'm hoping for, but I'm unable to find if there's any way to do that. edit: for 3 variables.</p> <p>Edit again:</p> <p>Using:</p> <pre><code>&lt;form&gt;&lt;input type='button' name='$name' id='$id' title='$number' onclick='ed(this.name,this.title,this.id)' value='Edit' /&gt;&lt;/form&gt; </code></pre> <p>sent the values of all 3 php variables to the javascript function.</p> <p>It's not pretty, but it works.</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.
    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