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
;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|