Basically; what I am trying to achieve is 'if and only if' an element in my static HTML form is checked; so if a checkbox is checked > then the user hits the 'submit' button. The items or checkboxes that are not checked, simply disappear, I have this with the below snippet of code.
$("input[type=checkbox]:not(:checked)").parent().hide();
OK, so the ones that are not checked hide correctly as they are supposed too, perfect! The problem is: I need the checkbox container div(s) to populate with unique HTML on the next page after the user has 'selected / checked' and then hit submit button. So currently on the next page; the non-checked items hide, and the form elements hide, so all that is perfect. So it's just the black (currently grey background) wrapper divs of the check boxes / items that are checked. But I just need to invoke custom HTML in each one.
Again; user flow: Static Homepage HTML form > user selects checkboxes > hit's submit > next page all non-checked items hide, check boxes themself all hide, but their respective wrapper containers remain - and I simply want custom HTML to appear in each at this point. As opposed to being blank So, the insertion of custom HTML in each of these divs at this point is my struggle
Below is the full pages code:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/bootstrap-theme.css">
</head>
<style>
#item1 {
padding: 20px;
width: 300px;
height: 100px;
text-align: center;
background: #ddd;
border-radius: 4px 4px 4px 4px;
box-shadow: 3px 3px 3px #333;
}
#item2 {
padding: 20px;
width: 300px;
height: 100px;
text-align: center;
background: #ddd;
border-radius: 4px 4px 4px 4px;
box-shadow: 3px 3px 3px #333;
}
#item3 {
padding: 20px;
width: 300px;
height: 100px;
text-align: center;
background: #ddd;
border-radius: 4px 4px 4px 4px;
box-shadow: 3px 3px 3px #333;
}
#item4 {
padding: 20px;
width: 300px;
height: 100px;
text-align: center;
background: #ddd;
border-radius: 4px 4px 4px 4px;
box-shadow: 3px 3px 3px #333;
}
.space {
padding-top: 10px;
padding-bottom: 10px;
border-radius: 4px 4px 4px 4px;
}
</style>
<body>
<div class="container" id="records" style="background-color:#fff; width: 400px; margin: 0 auto;">
<br/>
<div class="row" id="item1" class="box">
Item 1 Details for the PDF test.
<br>
<input type="checkbox" id="check1" name="sample[]" value="red" /> <em>This</em> is a checkbox1
<br />
</div>
<div class="space"></div>
<div class="row" id="item2" class="box">
Item 2 Details for the PDF test.
<br>
<input type="checkbox" id="check2" name="sample[]" value="red" /> <em>This</em> is a checkbox2
<br />
</div>
<div class="space"></div>
<div class="row" id="item3" class="box">
Item 3 Details for the PDF test.
<br>
<input type="checkbox" id="check3" name="sample[]" value="red" /> <em>This</em> is a checkbox3
<br />
</div>
<div class="space"></div>
<div class="row" id="item4" class="box">
Item 4 Details for the PDF test.
<br>
<input type="checkbox" id="check4" name="sample[]" value="red" /> <em>This</em> is a checkbox4
<br />
</div>
<div class="space"></div>
<center>
<div class="container1">
<div class="row">
<div class="col-md-8">
<p><a class="btn btn-primary btn-lg download-pdf" href="#" role=button>Download PDF</a>
</p>
</div>
</div>
</div>
</center>
<div id="print" style="background-color:#fff"></div>
<script type="text/javascript">
$("#container").css('background', '#fff')
$('.download-pdf').click(function() {
$("input[type=checkbox]:not(:checked)").parent().hide();
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.addHTML(document.getElementById('records'), function() {});
var file = 'test';
if (typeof doc !== 'undefined') {
doc.save(file + '.pdf');
} else if (typeof pdf !== 'undefined') {
(function() {
pdf.save(file + '.pdf');
// $("#item4").hide();
}, 2000);
} else {
alert('Error 0xE001BADF');
}
});
</script>
</body>
</html>
Here's another version, where you just specify your HTML inside divs with after-submit class:
Hope it helps. Just included all these lines:
So create a hash texts that will include copy per each container ID, as shown. Not the most beautiful version ever, but a fast response