Answer the question
In order to leave comments, you need to log in
How to print or save to PDF table?
I use a table that users fill out and, if necessary, add the number of lines they need. How can I make it so that after filling it out, the user can download it and save it as a PDF? Here is the code I am using:
<script type="text/javascript">
$(function() {
var tbl = $('table');
$('#add').click(function() {
tbl.children() //получаем детишек - TR/TBODY
.first() //берем первого
.clone() //клонируем
.appendTo(tbl) //добавляем в таблицу
.find('input') //получаем поля ввода
.filter(':text').val('') //выбираем текстовые поля (если кнопка удаления не input, то этого не надо)
.end() //в начало набора
.last().click(function() { //получаем кнопку удаления (если кнопка удаления не input, то ищем нужно вместо last())
$(this).closest('tr').remove() //удаляем добавленную строку
sum();
})
});
function sum()
{
var a = document.querySelectorAll('input[name="a[]"]'),
b = document.querySelectorAll('input[name="b[]"]'),
c = document.querySelectorAll('input[name="c[]"]'),
t = document.querySelector('.total');
t.innerHTML = [].reduce.call( a , function(s, el, i) {
c[i].value = (+el.value||0) * (+b[i].value||0);
return s + +c[i].value
},0).toFixed(2) + " руб.";
}
$('form').on('input', 'input[name="a[]"], input[name="b[]"]', sum)
});
< /script >
< /head>
< body>
< form action="" method="post">
< table>
<tr>
<td>
<input name="a[]" />
</td>
<td>
<input name="b[]" />
</td>
<td>
<input name="c[]" disabled="disabled"/>
</td>
<td>
<input type="button" value="Del" />
</td>
</tr>
< /table>
<span class="total"></span>
< /form>
< button id="add">Add</button>
< input type="submit" name="submit" value="Передать"><br>
< ?php
if (isset($_POST["submit"])){
if (empty($_POST['a[]'])){
echo "Нет данных!";
}
echo " ".$_POST['a[]']." ".$_POST['b[]']." ".$_POST['c[]']." ";
}
? >
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question