sashavalentina Posted May 18, 2021 Share Posted May 18, 2021 As i can't use css to make my auto numbering for my tables with css using TCPDF.I'm trying to use Javascipt to make this work. I read the documentation this and this on how to add javascript into my tcpdf. But i do not know why it does not work and it shows the error of Parse error: syntax error, unexpected 'var' (T_VAR) in C:\filepath\XAMPP\htdocs\filepath\customerinvoice.php on line 211 Can i know how can i define my 'var' in tcpdf? Or is not possible to add javascript in TCPDF? Please help me with this issue. Any help will be apprecialted. Thanks in advance This are my codes $htmlcontent .=' <table cellpadding="7" style="max-height: 1000px;"> <tr class="receiptcontent"> <td style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> </td> <td width= "30%" colspan="3" style="font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_name'].' </td> <td style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['product_code'].' </td> <td width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> '.$irow['quantity'].' '.$irow['quantity_unit'].' </td> <td width= "15%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['original_price'].' </td> <td width= "20%" style=" font-weight: normal;font-size: 12px;line-height: 17px;color: #000000;"> RM '.$irow['price'].' </td> </tr> </table> '; } This is the javascript i added in to implement auto numbering for my tables $js = var table = document.getElementsByTagName('table')[0], rows = table.getElementsByTagName('tr'), text = 'textContent' in document ? 'textContent' : 'innerText'; for (var i = 0, len = rows.length; i < len; i++) { rows[i].children[0][text] = i + ': ' + rows[i].children[0][text]; }; // Add Javascript code $pdf->IncludeJS($js); $pdf->writeHTML($htmlcontent); ob_end_clean(); $pdf->Output('customerinvoice.pdf', 'I'); Quote Link to comment https://forums.phpfreaks.com/topic/312732-how-do-i-add-javascript-in-tcpdf/ Share on other sites More sharing options...
Barand Posted May 18, 2021 Share Posted May 18, 2021 4 hours ago, sashavalentina said: I'm trying to use Javascipt to make this work. If only PHP had a way you could increment a count. $i = 0; $content = ' <style> td { font-weight: normal; font-size: 8px; line-height: 12px; color: #000000; } </style> <table id="receiptTable" style="max-height: 1000px;" > <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> <tr> <td width = "7%" > '. ++$i .' </td> <td width= "8%" > '.'xxxxxx'.' </td> <td width= "10%" > '.'xxxxxx'.' </td> <td width= "30%"> '.'123'.' '.'Kg'.' </td> <td width= "20%" > RM '.'123.45'.' </td> <td width= "20%" > RM '.'123.45'.' </td> </tr> </table> '; OUTPUT 1 Quote Link to comment https://forums.phpfreaks.com/topic/312732-how-do-i-add-javascript-in-tcpdf/#findComment-1586625 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.