I was trying to add a java-script to a page which is generated on the fly. I tried this, but it seems like it is not working.
<SCRIPT SRC=\"sorttable.js\"></SCRIPT>
I always have to inline javacode along with the html for it to work. Any clues ?
Well it depends on your quoting structure for the WHOLE thing. If you're printing this out in a uninterpolated heredoc, then
\"
just creates a bigger problem.or a q expression:
So you would have to show more of your context. But let me assure you: when I write out the tags the right way, my JavaScript files gets sourced into the page, just as I would expect.
qq()
is the equivalent of""
, but with matching delimiters. It is going to be your friend if you are outputing HTML or JavaScript.Note that you don't have to use
()
as delimiters, see perlop.If you are outputting JavaScript that is building HTML, you should be using jQuery or Ext. But either way you will be in the multiple-levels-of-escaping-hell. JSON::XS might make your life less painful. Also learn about here-documents:
The tricky bit about the above is that
$href
is a JavaScript variable, not a Perl variable. (Yes, JS identifiers may include$
.)Perhaps this link might be helpful: http://perlmeme.org/tutorials/cgi_form.html
It provides method of embedding a jsp function into the form-onsubmit as follow:
And there is a following link from Perl5 CGI library - support for Javascript, it's about linking javascript function to an event. http://cpansearch.perl.org/src/MARKSTOS/CGI.pm-3.60/cgi_docs.html#javascripting
Regards