I'm creating a perl-generated html form. It contains a number of javascript functions including a script that runs onLoad, another one onSubmit and multiple functions which use onBlur, onFocus etc... The form as generated works ok but none of the javascript functions. If I take the perl generated html and rename it as an html file, it all functions perfectly.

From research, I'm assuming I need to use "Content-type: application/x-javascript\n\n" but haven't been able to find any details. Does it go in the head section of the html immediately in front of all the javascript functions? Does it need to be repeated for each function? And/Or does it need to be embedded in the body wherever a javascript function is called? Or am I totally incorrect about what is needed? My experiments thus far have all failed and I suspect I'm missing something simple.

A sample, here is the onSubmit statement:
onSubmit="return (CompareD(this) && valisort(this));"
and here are the functions in the head of the html
<SCRIPT language="JavaScript"> function CompareD(thd){ //function details } </script> <SCRIPT language="JavaScript"> function valisort(pmp){ //function details } </script>
If someone could show me where/how to use the content type statement back and forth between javascript and html in this example, I would be eternally grateful! (I realize that some of the functions could be totally re-created in Perl but clientside onBlur and onFocus for instance would be difficult - at least for me!)

edited: Tue Dec 9 20:59:15 2003 by jeffa - code tags and formatting


In reply to embedding Javascript in perl generated html by waris

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.