title: Call Javascript function from Perl
body: <p>This should be simple - don't get what I'm doing wrong! This is a very basic test (I'm new to PERL and Javascript) - this is the CGI file:</p>
  
  <pre><code>#! /usr/local/bin/perl
  
  print "Content-type: text/html\n\n";
  print "&lt;html&gt;\n" ;
  print "&lt;head&gt;Hello\n";
  print '&lt;script type="text/javascript" language="javascript" src="wibble.js"&gt;\n';
  print "&lt;/script&gt;\n";
  print "&lt;/head&gt;\n";
  
  print "&lt;body&gt;\n";
  
  $fred = "Fred";
  $numb = 7;
  
  print &lt;&lt;TEST;
  
  &lt;p&gt;Starting...&lt;/p&gt;
  &lt;p&gt;&lt;script type="text/javascript" language="javascript"&gt;
  theText = "$fred";
  theNum = "$numb";
  document.writeln("Direct write...");
  document.writeln("Number is: " + theNum);
  document.writeln("Text is: " + theText);
  
  testWrite(theNum, theText);
  
  &lt;/script&gt;&lt;/p&gt;
  
  &lt;p&gt;...ending JS&lt;/p&gt;
  
  TEST
  </code></pre>
  
  <p>and in wibble.js:</p>
  
  <pre><code>function testWrite(num1, txt1)
  {
     document.writeln("In testWrite...");
     document.writeln("Number is: " + num1);
     document.writeln("Text is: " + txt1);
  }
  </code></pre>
  
  <p>In my browser, I get the first set of writeln's but my function is never called. The error on the webpage says 'Object expected' at line 15 (the <code>'print &lt;&lt;TEST'</code> line).</p>
  
  <p>I mostly suspect I haven't got the right path in my src element but I've tried every combination I can think of ('.', './', full path etc) - nothing works. The js file is in the same dir as the CGI file.</p>
  
  <p>(I actually originally had the function call with no parameters, hoping that theNum and theText are global and will still work (that was the original point of this test program)).</p>
  
  <p>Please put me out of my misery...</p>
  
  <p>As requested, here is source code from browser:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;script type="text/javascript" language="javascript" src="wibble.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;p&gt;Starting...&lt;/p&gt;
  &lt;p&gt;&lt;script type="text/javascript" language="javascript"&gt; 
  theText = "Fred";
  theNum = "7";
  document.writeln("Direct write...");
  document.writeln("Number is: " + theNum);
  document.writeln("Text is: " + theText);
  
  testWrite(theNum, theText);
  
  &lt;/script&gt;&lt;/p&gt;
  
  &lt;p&gt;...ending JS&lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is the actual output on the web page:</p>
  
  <pre><code>Starting...
  
  Direct write... Number is: 7 Text is: Fred 
  
  ...ending JS
  </code></pre>