Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Break and Dynamic Table 1

Status
Not open for further replies.

sharapov

MIS
May 28, 2002
106
US
Hello,

I am retrieving data from the database and displaying it inside HTML table. What I want to do is insert a page break every after every sixth row of the table (i.e. page break after row 6, 12, 18, etc.) by doing something like this: <tr style=&quot;page-break-after: always;&quot;>. Is it possible to do it with JavaScript? Keep in mind that since data is generated from database I can't assign ID's to the table's rows. Is there any other way?

Thanks.
 
If you're using ASP, you could try something like this:

<%
count=0
Do While Not rsMyRecordSet.EOF
count=count+1
%>
<tr<%
If count Mod 6 = 0 Then
Response.Write &quot;style=&quot;&quot;page-break-after: always;&quot;&quot;&quot;
End If
%>>
<td>
</td>
</tr>
<%rsMyRecordSet.MoveNext
Loop%>
 
adam0101,

Thanks for your help, but I need a JavaScript solution.
 
What are you using to write out the table from the db? Can you give an ID to the table itself?
 
I use PHP, and yes I can give ID to the table itself. Although I can assign page breaks with PHP when table is generated, I don't want to do it because my users interact with table by removing certain rows. After row is removed I don't want to send page back to the server to recalculate page break position, I want to do it only on the client's side using JavaScript.
 
I see... how about this then:

<html>
<head>
<script>
function setPageBreaks(){
var t=document.getElementById(&quot;myTable&quot;);
var rows= t.getElementsByTagName(&quot;tr&quot;);
for(var i=0;i<rows.length;i++){
if(i%6==0 && i!=0){
rows.style.pageBreakAfter=&quot;always&quot;
}
else{
rows.style.pageBreakAfter=&quot;auto&quot;
}
}
}
</script>
</head>
<body onload=&quot;setPageBreaks()&quot;>
<table id=&quot;myTable&quot;>
<tr>
<td></td>
</tr>
</table>
 
adam0101,

Thank you. It looks like it might work the way you describing it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top