Php solution
If you have something like
<form method="post" action="print.php"> <p>Select the records to be printed</p> <p> <input type="checkbox" name="records[]" value="1"><div class="record">Record 1</div><br> <input type="checkbox" name="records[]" value="2"><div class="record">Record 2</div><br> <input type="checkbox" name="records[]" value="3"><div class="record">Record 3</div> </p> </form>
You will automatically receive the $_POST['records'] array with all the values ββof the selected records in it in your PHP script print.php . (Note that this only works if the name of all the flags is the same and ends with [] )
Then the php script could do something like:
<?php foreach ($record in $_POST['records']) {
JavaScript and CSS
Another possible possibility would be to do all this through javascript. Therefore, you will need to check each checkbox if it will be checked when the print button is pressed, and then removes or hides all records that have not been checked.
A useful thing is the css media property, with which you can define additional styles that apply only to specific devices. This code can execute everything without javascript, except for the onclick="window.print()" attribute in your print button:
@media print { input{ display: none; } .record { display: none; } input[checked] + .record, input:checked + div.record { display: block; } }
Please note that I tested it only in Safari (where the pseudo-slot: verified leads to the desired result, not the attribute selector) and will work only for newer versions of browsers with css3 and selector .
source share