Hello monks,

I am trying to execute a javascript embedded in the Perl generated HTMl file but unable to do so. The Perl code is as follow:
print "Content-type: text/html\n\n"; print "<html>"; print "<head>"; print qq{<script>script src="ncbi.js"</script>}; print "</head>"; print '<body TEXT="#00325D">'; print '<select name="geneID" onchange="showName(this.value)">'; print '<option value="none" selected="selected">-----</option>'; print '<option value="54123">54123</option>'; print '<option value="21354">21354</option>'; print '<option value="11988">11988</option>'; print '</select>'; print qq{<div id="geneName"><b>Java return value will be'; listed her +e.</b></div>}; print "</body>"; print "</html>"; The javascript file is located in the cgi-bin dir on my linux machine +running Apache. I have chmod 755 so it can be executed. The Java scri +pt is as followed: <code> 1. var xmlHttp 2. function showName(str) 3. { 4. xmlHttp=GetXmlHttpObject() 5. if (xmlHttp==null) 6. { 7. alert ("Browser does not support HTTP Request") 8. return 9. } 10. var url="ncbi.cgi" 11. url=url+"?q="+str 12. url=url+"&sid="+Math.random() 13. xmlHttp.onreadystatechange=stateChanged 14. xmlHttp.open("GET",url,true) 15. xmlHttp.send(null) 16. } 17. function stateChanged() 18. { 19. document.getElementById("geneName").innerHTML = "Fetching XML fil +e..." 20. if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") 21. { 22. var response = xmlHttp.responseText 23. if (!response) { 24. document.getElementById("geneName").innerHTML="No data returned +!" 25. } 26. else { 27. document.getElementById("geneName").innerHTML=response 28. } 29. } 30. } 31. function GetXmlHttpObject() 32. { 33. var xmlHttp=null; 34. try 35. { 36. // Firefox, Opera 8.0+, Safari 37. xmlHttp=new XMLHttpRequest(); 38. } 39. catch (e) 40. { 41. // Internet Explorer 42. try 43. { 44. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 45. } 46. catch (e) 47. { 48. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 49. } 50. } 51. return xmlHttp; 52. }
without the line numbering of course. I have another perl script called ncbi.cgi also in the cgi-bin dir:
#! /usr/bin/perl $temp=$ENV{'QUERY_STRING'}; $test_path = "/var/www/html/test_file/"; # separate each keyword foreach ( split( /&/, $temp ) ) { # separate the keys and values ( $key, $val ) = split( /=/, $_, 2 ); # translate + to spaces $key=~s/\+/ /g; $val=~s/\+/ /g; # translate %xx codes to characters $key=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie; $val=~s/%([0-9a-f]{2})/pack("c",hex($1))/gie; } $file = $test_path . $val; $out = $test_path . $key; open FH, ">out"; print FH "I am here"; close FH; open FH, "$val" or die "Can not open for read: $val"; my $pid = <FH>; close FH; print $pid;
all three scripts are in the cgi-bin dir but after the html is loaded, clicking on the drop down list does not activate the java script for some reason. Do I need to install the java compiler and interpreter or something. Please help. Thanks.

In reply to Perl not running Javascript by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.