http://www.perlmonks.org?node_id=676162

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 ;