how to check/uncheck the checkboxes using jquery in python web.py
Question: I am using web.py framework to develop a small webpage that displays all the
records from a database.

Below is my code

**list_page.html**

    
    
    $def with ( select_query )
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>List Page</title>
    </head>
    <body>
     <form method="POST" action="/retrieve">
     <table border="1">
       <tr>
        <td>Select</td><td>Column_two</td><td>Column_three</td><td>Column_four</td><td>Column_five</td>
       </tr>
      $for r in select_query:
       <tr>
        <td><p align = "center"><input type="checkbox" id="$r.id" value="" name="$r.id"/></p></td>
        <td>$r.Listing_Name</td><td>$r.Address</td><td>$r.Pincode</td><td>$r.Phone</td>
       </tr>
     </table>
       <br/>
      <p><button id="submit" name="select_unselect">Select All/Unselect All</button></p>
      <p><button id="submit" name="submit">Retrieve</button></p>
    </form>
    

So from the above html page the results from the database will appear in the
form of a table.

Actually, i am trying to implement checking/unchecking the checkboxes with
jquery in python.

Below is my **index.py** code

    
    
    import web   
    render = web.template.render('templates/')
    db = web.database(dbn='mysql', db='Browser_Date', user='root', pw='redhat')
    urls = ('/',   'Listpage',)
    app = web.application(urls, globals())
    
    class Listpage:
    
        def GET(self):
            select_query = db.select('File_upload')
            return render.list_page(select_query)
    
        def POST(self):
            i = web.input(groups = {})
            ids =  i.keys()
            ........
            ........
            web.header('Content-Type','text/csv')
            web.header('Content-disposition', 'attachment; filename=csv_file.csv')
            return csv_file.getvalue()
    
    if __name__ == "__main__":
        web.internalerror = web.debugerror
        app.run() 
    

The concept is the web page(html displayed above) will display the records
from the database, and based on selection of the records by
checking/unchecking and after clicking a `retrieve` button, a csv file will be
generated with the selected records on the page

So now i am trying to check/uncheck all the checkboxes at a time using jquery
, but dont know how to start and where to write the jquery code in the above
html code, i googled on jquery but its really confusing, so I approached SO.

Basically I am newbie in web developing and no idea on implementing/using
jquery, can anyone please let me know on how to implement the
checking/unchecking the checkboxes functionality in the above mentioned
code/html file? so that i can extend the code easily further


Answer: Python, web.py, html, javascript and jQuery ARE confusing.

It is powerful, but also quite confusing when you first try to get your head
around it. You have to think in terms of a hybrid, multi-platform application,
since you're really merging at least three distinct technologies into one user
experience.

The web.py server and templates do nothing more than deliver STATIC content to
a web browser. That's what a web server does. The templating code allows you
to make decisions, in python on the server side, based on querystring
arguments and such, but ultimately all you're really doing is delivering
_code_ (html+javscript) to another interpreter (the browser). PHP, Ruby,
ASP... they're all the same in this regard - building a page for the browser.

Once the request is delivered, the browser takes over. If a user clicks
something, it'll be the javascript interpreter that handles that click.
Javascript (or jquery) can either a) redirect the user to a different page, b)
manipulate things locally or c) submit/receive information via ajax.

(jQuery IS javascript... it's just an awesome way to simplify some of the
eccentricities of pure javascript.)

So, a typical workflow:

  * user requests `http://localhost/index`
  * web.py delivers the home page via render()
  * browser draws the home page html, and processes any onload() javascript (page is now idle, waiting for user interaction)
  * user clicks something, javascript function evaluates what was clicked and decides to request more data
  * javascript creates and issues an XmlHttpRequest (or in jQuery... $.ajax() )
  * web.py handles the request, let's say it was to /home_tab_2 
  * javascript updates the page (with element.innerHTML() or in jquery `$(element).append()` or whatever)

I hope this helps, as writing this down really helped me with my first ajax
application.

