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

I need to get this JavaScript "Back" function to workn in my CGI script.
I would like it to work in my CGI script where I hit the "Back" button and it goes back to the previous form I was on similiar to the Back button on the browser. This doesnt seem to be working. Any suggestions on what I am doing wrong?
print "<p><h1>Your form was sent.</h1></p>\n"; print "<a href="javascript:history.back()">Back to the form</a>\n";

Replies are listed 'Best First'.
Re: JavaScript in CGI
by broquaint (Abbot) on Oct 29, 2002 at 18:58 UTC
    You've got conflicting quotes in the second statement, so just change the quoting construct e.g
    print qq[<a href="javascript:history.back()">Back to the form</a>\n];
    See perlop for more info on alternative quoting methods.
    HTH

    _________
    broquaint

      broquaint, Thank you for your quick reply and answer!
      I am not familiar with the "qq" and puttin the brackets around the print statements. Are these some CGI functions and syntax?? How can I find more about this?
        qq has the same effect of double quotes. It may be used to tell perl to work as if the string inside the qq range is enclosed with '"'. The difference is that the charecter immediately following qq will be the delimiter, instead of '"'. You can use nearly anything that's not whitespace. If you use some kind of embracing character, such as '{', '[', or '(', then you have to close with the relevant closing brace.

        More operators such as qq are discussed in perlop, as was referenced by broquaint. To list a few:
        q - same effect as using single quotes (')
        qw - break words to a list (qw(foo bar) == ("foo","bar");)


        -nuffin
        zz zZ Z Z #!perl
Re: JavaScript in CGI
by Speedy (Monk) on Oct 29, 2002 at 20:17 UTC

    Another very convenient format to use in CGI scripts is the "Here" document, as described, for example, in the Camel Book Programming Perl, 3rd edition, pp. 66-67. The glossary in that book comments that "in Perl here documents are just a fancy form of quoting."

    In your case something like

    print <<EOF; <p><h1>Your form was sent.</h1></p> <a href="javascript:history.back()">Back to the form</a> EOF

    where the 'terminator' of the "here" document is defined by the word after the << and the text between that line and the terminating line (in this case
    EOF
    on a line by itself in the first column, followed immediately by a return) is printed unchanged, including the internal quotes AND the return at the end of each line (so you don't have to put the "\n" stuff in).

    This format makes it much easier to work with HTML code in the midst of Perl, at least until you are ready for templates and separating the HTML display code entirely from the Perl logic.

    Live in the moment