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

Greetings monks,
I am developing a page and want to have a Javascript alert popup of the user requests a bit of data, the data I want to supply is found in @files_to_remove but Javascript requires the argument sent to alert() be in single quotes, and as a result perl notices the single quotes and gives the name of my array and not its value.

Any thoughts?

my $files_to_remove = "The following files will be removed from your a +ccount if they exist: \n" . join(", ", @files_to_remove); print <<END; <script language="JavaScript"> function details() { alert("$files_to_remove"); } </script> .... [<a href="javascript:details('')"class="linkmaroonsm">Details</a>] .... END
that is what I have got so far. And it 'works' but the newline does not show up, which makes the whole thing actually readable. I realize this is more of a Javascript question then a Perl one, but.....

jcpunk

by the way thanks for all the help that was, is, and will be

Replies are listed 'Best First'.
Re: javascript, perl, and single quotes
by artist (Parson) on Jul 03, 2003 at 20:03 UTC
    First: You are using Javascript which was formally known as LiveScript by Netscape and currently also known as ECMA script and not Java by Sun Microsystem.

    When you use $file_to_remove you interpret the "\n", and you need to escape that in order to appear in alert(). So put

    from ...your accunt if they exist: \\n". join ... 

    artist.

      I've often wondered why a group of European Computer Manufacturers think they have the right to rename Netscape's scripting language after themselves...
      Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats.

      -Howard Aiken

        God knows maybe it was not "European Computer Manufacturers Association" but European Carton Makers Association ;-)

        Jenda
        Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
           -- Rick Osborne

        Edit by castaway: Closed small tag in signature

      thank you that is it exactly (sorry for the not terribly perl related post)
      thank you for spending your time answering that
      jcpunk

      by the way thanks for all the help that was, is, and will be

OT: CSS Police
by TGI (Parson) on Jul 04, 2003 at 00:53 UTC

    In your html snippet you've got an anchor tag with a class called linkmaroonsm. I assume this means that anything with that class will be rendered with a rule that looks like this:

    .linkmaroonsm { font-size: small; color: maroon; }

    I think you are missing the point of stylesheets. You should be applying classes that describe what something is, not how it should look. If it makes you feel any better, this is a common mistake. I did it when I first started using stylesheets too.

    Instead of using classes like biggreenblink you should use names like annoying. That way if you decide that you want your annoying blinking green text to be pink instead, you don't need to change your class name.

    In the case of linkmaroonsm you might want to use something like:

    A.details { font-size: small; color: maroon; }

    Sorry for the off-topic post, but I see this sort of mistake all too frequently. When used properly, CSS makes life much easier. If you fall into the trap of naming your classes for how they look, you may as well be using font tags. I hope you found this useful.


    TGI says moo