Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl Generating error on display.

by Anonymous Monk
on Mar 25, 2008 at 17:03 UTC ( #676162=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks!

I am building an application that needs a table row added dynamically, well the code works fine if it is an html file, but I want this html to be inside of a Perl code. The problem is that, there is something that Perl donít like, I can see it, maybe someone of you had a similar problem like that and could give a hand on this one!

Here is the code and thank you very much!!!


#!/perl/bin/perl.exe use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); print header(); print <<HTML; <html> <head> <title>Add or Remove Rows Dynamically</title> <script type="text/javascript"> <!-- var count = 1; var nRows = 2; function addRow() { var tBody = document.getElementById('theBody'); var newRow = document.createElement('tr'); var col1 = document.createElement('td'); var col2 = document.createElement('td'); var col3 = document.createElement('td'); var rA = document.createElement('a'); newRow.setAttribute('id', 'n' + count); rA.setAttribute('href', 'javascript:removeRow(\' +n' + count + '\');'); rA.appendChild(document.createTextNode('Remove')); col1.appendChild(document.createTextNode('Col 1 Row ' + + nRows)); col2.appendChild(document.createTextNode('Col 2 Row ' + + nRows)); col3.appendChild(rA); newRow.appendChild(col1); newRow.appendChild(col2); newRow.appendChild(col3); tBody.appendChild(newRow); count++; nRows++; } function removeRow(rowId) { var tBody = document.getElementById('theBody'); tBody.removeChild(document.getElementById(rowId)); nRows--; } --> </script> </head> <body> <table border=1> <tbody id=\"theBody\"> <tr> <td>Policy Number:</td> <td><input type=text name=policy value=\"\"></td> </tr> </tbody> </table> <p><a href="javascript:addRow()">Add Row</a></p> </body> </html> HTML ;

Replies are listed 'Best First'.
Re: Perl Generating error on display.
by zer (Deacon) on Mar 25, 2008 at 17:33 UTC
    your code works fine. The problem you may be coming across is your shebang line. It looks like you mixed linux with windows.
    #!/perl/bin/perl.exe

    for a typical linux machine it would look similar to #!/usr/bin/perl. And for windows it would be the full path to the program.

    What is the error that you are getting?

      Sad, sad I am on Windows!
Re: Perl Generating error on display.
by superfrink (Curate) on Mar 25, 2008 at 19:12 UTC
    Are you seeing any error message anywhere? For example in the browser window or the server logs?

    Does the page load but the javascript doesn't seem to work? If so load both the CGI and HTML pages in your web browser. Save each webpage to a separate file and compare the two saved files.

    Try requesting the CGI and HTML pages using wget -S to see the headers sent by the server. Maybe you need to specify the Content-type in the print header(); call.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://676162]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2022-09-29 20:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?