title: passing a php variable into javascript function
body: <p>I am trying to pass a php value, obtained from a join query, to a javascript function. The javascript function will open a new window and show some data based on the passed value.My query works fine but the php value is not passed to the JS function.</p>
  
  <p>My code :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
     function product(var) {
      window.open( "view_product_info.php?var", "myWindow", 
      "status = 1, height = 300, width = 300, resizable = 0" )
      }
   &lt;/script&gt;
  
  \\ the line where i am trying to pass the php varibale
  
   echo '&lt;td align="center" &gt;&lt;a href="javascript:product('.$product_id.');"&gt; &lt;br/&gt; '.$row['product_name'].'&lt;/a&gt;&lt;/td&gt;';
  </code></pre>
  
  <p>why the php value $product_id is not passed to the product function.</p>
  
  <p>Thanks in advance.</p>
  
  <p>The code:</p>
  
  <pre><code>     &lt;script type="text/javascript"&gt;
         &lt;!--
      function product(var) {
      window.open( "view_product_info.php?id", "myWindow", 
       "status = 1, height = 300, width = 300, resizable = 0" )
        }
       function company() {
         window.open( "index.php", "myWindow", 
          "status = 1, height = 300, width = 300, resizable = 0" )
     }
       function category() {
          window.open( "index.php", "myWindow", 
       "status = 1, height = 300, width = 300, resizable = 0" )
   }
  </code></pre>
  
  <p>//-->
            </p>
  
  <pre><code>      &lt;?php include("includes/header.php"); 
  
  
         $search = $_POST['search'];
         $sql= "my query1..";
  
         $sql2= "my query2";
  
         $result=mysql_query($sql);
         $result2=mysql_query($sql2);
       if($result) {
              echo '&lt;center&gt;';
      echo '&lt;table cellpadding="0" cellspacing="0" border="1" width="100%"&gt;';
      echo '&lt;tr&gt;&lt;th&gt;Sr No.&lt;/th&gt;&lt;th&gt;Product Name&lt;/th&gt;&lt;th&gt;Company      Name&lt;/th&gt;         &lt;th&gt;Category&lt;/th&gt;&lt;/tr&gt;';
                 $number=1;
                   while ($row = mysql_fetch_array($result)){
                  $row2 = mysql_fetch_array($result2);
                  echo $product_id=$row2[product_id];
  
         echo '&lt;tr&gt; ';
          echo '&lt;td align="center" &gt;'.$number.'&lt;/td&gt;';
  
  
                       echo '&lt;td align="center" &gt;&lt;a href="javascript:product('&lt;?= $product_id?&gt;')"&gt; 
  </code></pre>
  
  <p><br/>''';</p>
  
  <pre><code>            echo '&lt;td align="center"&gt;&lt;a href="javascript:company()" &gt;&lt;br/&gt;  '.$row['company_name'].'&lt;/td&gt;';
  echo '&lt;td align="center"&gt;&lt;a href="javascript:category()" &gt;&lt;br/&gt;  '.$row['category_name'].'&lt;/td&gt;';
  
     $number=$number+1;
  
            }echo '&lt;/tr&gt;';
       echo'&lt;/table&gt;';
            echo'&lt;/center&gt;'; 
  
  }
           else {
         echo "No data found";
      //echo mysql_error();
  
         }
         }
        }
       ?&gt;
  </code></pre>