title: How to call a javascript function from a different php file
body: <p>I would like to call a javascript function (included inside a html file: index.html) from a php file (xyz.php). 
  So, when i click on a link inside the xyz.php page, it will call the javascript function from index.html. </p>
  
  <p>Something like: </p>
  
  <pre><code>echo '&lt;a href="#" onclick="index.html.someFunction(e)"&gt;&lt;/a&gt;';
  </code></pre>
  
  <p>It somehow needs to adress index.html, where the function is located. </p>
  
  <p>EDIT:</p>
  
  <p><strong>Index.html</strong></p>
  
  <pre><code>&lt;html&gt;
   &lt;head&gt;    
   &lt;/head&gt;
   &lt;body&gt;
  &lt;button id="search_button" type="submit" value= "Search" onclick= "return getOutput()"&gt;Search&lt;/button&gt;
  
  &lt;div id="output" style="width:395px; height:150px; overflow: auto; background = #969696" &gt;    &lt;/div&gt;
   &lt;/body&gt;
  
   &lt;script&gt;    
  
  
      //THIS DISPLAYS THE CONTENT OF MY PHP PAGE INSIDE THE DIV FIELD
      function getOutput() {
        getRequest(
            "xyz.php?eingabe=123&amp;eingabe2=File.csv", // URL for the PHP file
             drawOutput,  // handle successful request
             drawError    // handle error
        );
        return false;
      }
      function getOutput(link) {
        getRequest(
            link, // URL for the PHP file
             drawOutput,  // handle successful request
             drawError    // handle error
        );
        return false;
      }
  
      // handles drawing an error message
      function drawError() {
          var container = document.getElementById('wagoartikelnr2');
          container.innerHTML = 'Bummer: there was an error!';
  }
      // handles the response, adds the html
      function drawOutput(responseText) {
          var container = document.getElementById('wagoartikelnr2');
          container.innerHTML = responseText;
              }
      // helper function for cross-browser request object
      function getRequest(url, success, error) {
          var req = false;
          try{
              // most browsers
              req = new XMLHttpRequest();
          } catch (e){
              // IE
              try{
                  req = new ActiveXObject("Msxml2.XMLHTTP");
              } catch(e) {
                  // try an older version
                  try{
                      req = new ActiveXObject("Microsoft.XMLHTTP");
                  } catch(e) {
                      return false;
                  }
              }
          }
          if (!req) return false;
          if (typeof success != 'function') success = function () {};
          if (typeof error!= 'function') error = function () {};
          req.onreadystatechange = function(){
              if(req.readyState == 4) {
                  return req.status === 200 ? 
                      success(req.responseText) : error(req.status);
              }
          }
          req.open("GET", url, true);
          req.send(null);
          return req;
      }
  
  
   &lt;/script&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p><strong>XYZ.PHP</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;?php
  
  $vergleich = $_GET["eingabe"];
  $datei = $_GET["eingabe2"]; 
  
  
  
  
   $temp2a = array("0.1.2.4", "0.1.2.3", "0.1.2.2");
  
  
  for ($i = 0; $i &lt; count($temp2a); $i++) {
  
                  $URL = "xyz.php?eingabe=',temp2a[$i],'&amp;eingabe2=',$datei,";
                  echo '&lt;a href=',temp2a[$i],' onClick= "index.html.getOutput($URL)"&gt;&lt;/a&gt;';
              } 
  ?&gt; 
  
  &lt;body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>