I'm using the PHP CodeIgniter framework.
The problem is that I want the user to check those fields that they have entered and approved by selecting checkbox then submitting the form.
Like these are the fields.
<tr>
<td>Remarks </td>
<td><textarea name="particular" rows="3" class="save_record autosuggestship"></textarea></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Custom Reference No.</td>
<td><input type = 'text' name = 'custom_ref_no' class = 'save_record autosuggestship' id="custom_ref_no" /></td>
<td>Date</td>
<td><input name = 'costom_date' type = 'text' class = 'save_record date_class autosuggestship' id="costom_date" /></td>
</tr>
<tr>
<td>
<p> Container Information </p>
</td>
<td>
And this the Checkbox to approve.
<tr>
<td>Approve</td>
<td><input type="checkbox" id="Approve" /></td>
<td> </td>
<td align="left"> </td>
</tr>
Uses jQuery: try inserting this in your page wrapped in <script></script>
tags and including jQuery.
$(document).ready(function() {
$('form input[type=submit]').on('click', function(e) {
e.preventDefault();
if($('#Approve').attr('checked') == 'checked') {
$('form').submit();
}
else {
alert('You must check the Approve checkbox to continue!');
}
});
// if the user presses enter.
$('form').on('keyup', function(e) {
if(e.which == 13) {
$('form').submit();
}
});
});
In PHP (make sure you give your input a name="Approve"
:
if(isset($_POST['Approve']) {
// they have ticked the checkbox.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With