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

i have doubt regarding how to insert html and java script code inside perl.. i have tried this code it is creating html page and showing web page in IE but it is not working (after creation )dynamically... i have one more question regarding this if i run this as "name.html"this is giving out put only on firefox not in IE,can any body tell me the reason why it is behaving like that.. thanks.
#!d:/perl/bin/perl print "Content-Type: text/html\n\n"; print "<html> <head>\n"; print "<body>\n"; print "<script type=\"text/javascript\">\n"; print "function changedays(x) {\n"; print " var y=x;\n"; print " if(y == \"February\"){\n"; print " document.getElementById(\"3\").style.visibili +ty=\"hidden\";\n"; print " document.getElementById(\"4\").style.visibili +ty=\"hidden\";\n"; print " }\n"; print " else{\n"; print " document.getElementById(\"3\").style.visibili +ty=\"visible\";\n"; print " document.getElementById(\"4\").style.visibili +ty=\"visible\";\n"; print " }\n"; print "}\n"; print " </script>\n"; print " </head> \n"; print " <body bgcolor=\"lightgreen\">\n"; print " <p style=\"font-family:verdana;font-size:75%;colo +r:red\">\n"; print " <center>\n"; print " <p style=\"font-family:verdana;font-size:250%;col +or:red\"> <b>Day/Weekly Activity Report</b>\n"; print "</p>\n"; print "<TABLE BORDER=0 cellspacing=20>\n"; print " <center>\n"; print "<b>Month:</b>\n"; print "<select name=\"month\" id=\"res\" onchange=\"change +days(this.options[this.selectedIndex].value)\">\n"; print "<option value=\"january\">January</option>\n"; + print "<option value=\"February\">February</option>\n"; + print "<option value=\"March\">March</option>\n"; + print "</select>\n"; print "<b>Date:</b>\n"; print "<select name =\"fromdate\" id=\"rest\" >\n"; + print "<option id=\"1\">1</option>\n"; print "<option id=\"2\">2</option>\n"; print "<option id=\"3\">3</option>\n"; print "<option id=\"4\">4</option>\n"; print "</select>\n"; print "<input type=\"submit\" value=\"Submit\">\n"; print "</TABLE>\n"; print "</body>\n"; print "</html>\n";

Replies are listed 'Best First'.
Re: insert html with javascript inside perl
by marto (Cardinal) on May 07, 2007 at 12:06 UTC
    You seriously need to spend time checking what you are doing. Firstly this even thought this page is static you are using Perl to generate it, why not use HTML::Template or something similar. Secondly did you even read the HTML you are generating? Lets look at some of the tags:
    <html> <head> <body> <script /> </head> <body> Page content </body> </html>
    Slightly messed up tag order and two <body> tags? This is not a Perl problem, check your HTML and you may want to do some research on Internet Explorer and some of its more interesting html/JavaScript 'Features'.
    For example I believe IE has an issue with excessive white space print "function changedays(x)              {\n";

    Update: Fixed formatting problem, added whitespace example.

    Martin
Re: insert html with javascript inside perl
by Cody Pendant (Prior) on May 07, 2007 at 11:54 UTC
    The JavaScript works just fine as far as I can see. If February is chosen in one menu, items 3 and 4 disappear from the other menu. What did you think it did?

    As above, you really need to learn about HERE documents, or even better, a template system.

    What's more of a mystery is why you're printing this page out with perl at all. You're just using perl to dump HTML to the browser. Why not just have a static page?



    ($_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
    =~y~b-v~a-z~s; print
Re: insert html with javascript inside perl
by derby (Abbot) on May 07, 2007 at 12:03 UTC

    ++ to all the others about the use of HERE docs (or some templating engine or at least CGI). You're code works fine from the server/perl perspective. I can see in firefox how 3 and 4 disappear but in IE (6.0) they do not. I would suggest a good javascript forum (if I knew of one).

    -derby
Re: insert html with javascript inside perl
by ahmad (Hermit) on May 07, 2007 at 11:16 UTC

    Hello,

    i did not understand what your problem is?

    it would be better if you can explain more on what you want to do

    anyway take a look at HERE Documents it might help you out