swarddb has asked for the wisdom of the Perl Monks concerning the following question:

I am getting an error in a onmouseover attempt on a web page that i can't get to work out.
print "<a href=\"index.html\" ONMOUSEOVER=\"javascript:pop('Avaerage l +enght of game played','#CCCCCC')\"; ONMOUSEOUT=\"kill()\">AVERAGE</a> +";
Suffice to say I have defined all the called objects. But it still pukes on the pop within the string. I have talk to Java peoples that claim it has something to do with Perls quotation particulars. Please help. (I will be glad to enclose the complete code if ness but I am hoping this snip will work.)

Replies are listed 'Best First'.
Re: Java script question
by myocom (Deacon) on Aug 02, 2001 at 22:24 UTC

    I can't say that I'm a javascript expert, but I do know a bit of Perl that will at least make this more readable. Use the q quotelike operator, and you won't need to escape all of your double-quotes.

    print q|<a href="index.html" ONMOUSEOVER="javascript:pop('Average leng +th of game played','#CCCCCC')"; ONMOUSEOUT="kill()">AVERAGE</a>|;

    Update: Naturally, add the standard "use CGI!" advice...

Re: Java script question
by !me (Acolyte) on Aug 02, 2001 at 22:20 UTC
    on the mouseover event you dont need "javascript:" so your code should look like
    print "<a href=\"index.html\" ONMOUSEOVER=\"pop('Avaerage lenght of ga +me played','#CCCCCC')\" ONMOUSEOUT=\"kill()\">AVERAGE</a>";
      It still dies on the pop according to Visual Dev editor. that may mean absolutly nothing however.
        one thing you should use to debug this is netscape!

        type in
        javascript:
        in the url field
        gets you the javascript debugger
        it should tell you what the error is
        in a much clearer way than ie and/or visualdev would

        one thing:
        you dont need the
        javascript:
        if the javascript function is in the html file {or perl output}
        aka
        onmouseover=pop('Avaerage lenght of game played','#CCCCCC')

        also you might notice the semi colon after your dbl quote
        thats not right and since your only using one
        function , in javascript you dont need that semi colon

        here is your code reworked and running:
        <html> <head> <script> function kill() { alert('kill'); } function pop (text, color) { alert (text +" "+ color); } </script> </head> <body> <a href="js.html" ONMOUSEOVER="pop('Avaerage lenght of game played','# +CCCCCC')" ONMOUSEOUT="kill()">AVERAGE</a> </body> </html>

        always try to build a flat file to test javascripts
        before inserting them into perl code
        hope that helps
        Well, If it is still generating errors you probably should post the pop and/or kill functions. I tested the small (corrected) block above and it worked fine for me ( using fake pop/kill functions )
Re: Java script question
by tachyon (Chancellor) on Aug 03, 2001 at 18:15 UTC

    For browser compatibility I thought you needed to use 'onMousover' - ie camel hump notation as shown rather than all caps. I only have IE here and it works on all caps which suprised me. I'm sure some versions of Netscape crack the sads if you don't use this format but don't nave Netscape handy, or Linux :-(

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print