Forum for discussing general topics related to Couch.
2 posts Page 1 of 1
Hello All,
I have a student list. In the list i have added a checkbox for each row. The checkbox value is the k_page_id.
I want to send the checked checkbox ids to another template and collect it in cms:gpc there.
Then process the code in that template for each id.
How can this be done?
Any help!
Regards,
GenXCoders
Image
where innovation meets technology
Hello @All,
I have the solution to the question I asked, hence I am posting the reply for my future reference and for others too, if needed.

I have a student list. In the list i have added a checkbox for each row. The checkbox value is the k_page_id.

Code: Select all
<table border="1">
    <thead>
        <tr>
            <th>Select</th>
            <th>Student Name</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <cms:pages masterpage='template,php' order='asc'>
        <tr>
            <td><input name="student_cb" class="student_cb" type="checkbox" value="<cms:show k_page_id />" /></td>
            <td><cms:show firstname /> <cms:show surname /></td>
            <td>Some Action</td>
        </tr>
        </cms:pages>
    </tbody>
</table>


I want to send the checked checkbox ids to another template and collect it in cms:gpc there.

After selecting the required checkboxes, click the HTML button defined as:
Code: Select all
<button class="btn btn-danger" type="button" id="process-students">
    <i class="fa fa-file-pdf-o"></i> ACTION
</button>


Here the id, #process-students is the key factor, to invoke an AJAX call on button click.
The AJAX Call is defined as:
Code: Select all
    $("#process-students").click(function() {
        var ids = [];
        $('.student_cb:checked').each(function(i, e) {
            ids.push($(this).val());
        });
        $.ajax({
            url: "ajax-processing.php",
            type: "POST",
            data: {
                'id': ids.join()
            },
            success: function(response) {
                if  (response != '') {
                    // Do Something
                }
            }
        });
    });


In the AJAX script, the
$('.student_cb:checked').each(function(i, e) {
ids.push($(this).val());
});

part iterates through the table checking the status of all checkboxes and push-ing the values in the id array variable.
while in the AJAX Script, the
data: {
'id': ids.join()
}

join() function creates a comma separated value list that is POSTed to the defined url in the AJAX function.

The posted values can then be collected in the ajax-processing.php file as:
Code: Select all
<cms:set selected_checkbox_ids = "<cms:gpc 'id' method='POST' />" scope="global" />


This type of code can be used to perform bulk operations on a list of students, employees, contracts, publishing or un-publishing pages, etc. from the frontend. The logic to be implemented lies in the ajax-processing.php file.

Regards,
GenXCoders
Image
where innovation meets technology
2 posts Page 1 of 1