Handle checkbox with pagination

Discussion in 'JavaScript' started by laspal, Dec 9, 2008.

  1. #1
    Hi,
    here is my code:
    <form name="generatereport" method="POST" action="">
    <table id="companieslisting">
    {% for companies in companylist.object_list %}
    <tr>
    <td><input type="CHECKBOX" id="" name="selected_companies_id_list" value="{{companies.id}}" onchange='storeValue(this)' /></td> </tr>
    {% endfor %}
    </table>
    <input type="submit" value="Generate Report" name="Send" class="add-company-submit"/ >
    </form>

    <script type="text/javascript">
    function storeValue(what) {
    var myarray = new Array()
    for(var i=0; i < document.generatereport.selected_companies_id_list.length; i++){
    if(document.generatereport.selected_companies_id_list.checked){
    myarray = document.generatereport.selected_companies_id_list.value}
    }

    What I want is to get the list of selected checkbox. Right now I am getting the list of selected checkbox for that page.
    I mean I am using pagination so the list which I am getting is for that particular page.

    How can I solve this problems

    Thanks.
     
    laspal, Dec 9, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi,
    I'm not sure I got what you mean. But from the code, everytime user check/uncheck checkbox (maybe better to use onclick event than onchange) all checkboxes in the form are scanned and your 'myarray' get all selected ids. Dont know what are you going to do with the array after, but if you want to keep that value of myarray for the previous/next page, use either AJAX to save it either in DB, or just in session or try to append the array into location.href under some parameter, everytime user is browsing the pages. But it's not really clear to me what is your problem, so maybe I'm totally somewhere else...
     
    lp1051, Dec 10, 2008 IP