title: Pass PHP Variable to Javascript function from Button
body: <p>Here's what I got.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function show_confirm(id)
  {
  var r=confirm("Are you sure you want to duplicate this record?");
  if (r==true)
    {
    window.open ("http://domain.com/process.php?duplicate=id","mywindow");
    }
  else
    {
    alert("Record Not Duplicated.");
    }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>then below that:</p>
  
  <pre><code>$query = "SELECT * FROM contacts";
          $result = mysql_query($query);      
  
          while($row = mysql_fetch_row($result)){
  
                  $id = $row[0];
                  $company = $row[3];
                  $firstName = $row[4];
                  $protection = $row[20];
  
              echo '&lt;tr&gt;';
              echo '&lt;td width="120" align="middle"&gt;&lt;font color="black"&gt;&lt;b&gt;' . $company . '&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;';
              echo '&lt;td width="120" align="middle"&gt;&lt;font color="black"&gt;&lt;b&gt;' . $firstName . '&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;';
  
              echo "&lt;td width='120' align='middle'&gt;&lt;a style='text-decoration: none;' href='http://domain.com/index.php?id=14&amp;edit=" . $id . "'&gt;&lt;span style='font-family:Helvetica; color:black;'&gt;Edit&lt;/span&gt;&lt;/a&gt;";
              echo "&lt;td width='120' align='middle'&gt;&lt;input type='button' onclick='show_confirm($id)' value='Duplicate' /&gt;";
  
              echo "&lt;/td&gt;";               
              echo '&lt;/tr&gt;';
  
  
          }
          ?&gt;
  </code></pre>
  
  <p>The problem is this:</p>
  
  <pre><code>echo "&lt;td width='120' align='middle'&gt;&lt;input type='button' onclick='show_confirm($id)' value='Duplicate' /&gt;";
  </code></pre>
  
  <p>This is supposed to be a button where when the user clicks it, it says <code>"are you sure you want to duplicate?"</code> then if the use clicks yes, it to <code>http://domain.com/process.php?duplicate=(whatever the ID is)</code></p>
  
  <p>The problem is my variable (in php) <code>$id</code>, isn't getting passed to the javascript <code>window.open</code>. I need the <code>$id</code> from the row to be passed along in the javascript. I tried writing it, but it didn't work. Doesn't even see the variable. I've tried manually entering in <code>&lt;?php echo $id; ?&gt;</code> and that didn't work as well.</p>
  
  <p>Thank you</p>