Sign up ×

I am using framework for creating small web pages.I had a basic html that has a form with four checkbox fields as below


$def with ( )
   <form method="POST" action="/checkboxes">
      <p>check_1     <input type="checkbox" id="curly_1" value="" name="curly_1"/></p>
      <p>check_2     <input type="checkbox" id="curly_2" value="" name="curly_2"/></p>  
      <p>check_3     <input type="checkbox" id="curly_3" value="" name="curly_3"/></p>  
      <p>check_4     <input type="checkbox" id="curly_4" value="" name="curly_4"/></p>      
      <button id="submit" name="submit">Submit</button>

import os
import sys
import web
from web import form

render = web.template.render('templates/')

urls = (
  '/checkboxes',   'Checkboxes',  
app = web.application(urls, globals())

class Checkboxes:

    def POST(self):
        i = web.input(groups = {})
        print i,">>>>>>>>>>>>"
        raise web.seeother('/checkboxes')

if __name__ == "__main__":
    web.internalerror = web.debugerror  


<Storage {'curly_3': u'', 'submit': u'', 'curly_4': u'', 'curly_1': u'', 'groups': [], 'curly_2': u''}> >>>>>>>>>>>>

So from the html view i can see four checkbox fields, i had checked all checkboxes and clicked the submit button, now it should come to Checkboxes class and should print the result of the input(checkboxes that are checked) in post method as i had shown above.

But in result i am getting empty string(No result) as shown above,

can anyone please let me know whats wrong in the above code

Also how to get the values of checkboxes that are selected ?

share|improve this question

2 Answers 2

The presence of a checkbox element's name in the dictionary returned by web.input() indicates the field was checked. Otherwise, it won't be present in the dictionary. Try checking a subset of the four checkboxes on your form and I think you'll see what I mean.

More details:!searchin/webpy/checkbox/webpy/PVBdPv7kGDM/IqgLptUEN-EJ

share|improve this answer
:Thanks for ur reply, what i want is it should display a vaue of TRUE or FALSE based on whether it is checked or not. How can we achieve this ? –  shiva krishna Nov 15 '12 at 9:09
You can obtain the equivalent of an explicit True or False value by checking existence of any given checkbox in the dictionary returned by web.input(). For example, instead of looking to see if curly_1 is checked like this: if i['curly_1']: which won't work because curly_1 will be present only when checked, you could use logic like this: if 'curly_1' in i: because the desired key will only be present in the returned dictionary if the corresponding checkbox was checked. –  Marc Cohen Nov 15 '12 at 16:17
yes of course,but somewhere i had seen getting those values(True or False),so asked about how we can get True or False values when clicked the check box?is there any some other way of getting the values as True or False,because i am designing a page that displays all the records from database,now user can select some appropriate records by checking the checkbox and will click retrieve button(that creates a csv file with only records that are checked).So what i am trying is when the user select the record by checking it,i can check the values of the records that are true and will retrieve that –  shiva krishna Nov 16 '12 at 5:38
I don't understand -- if you simply want true/false values, you could create another dictionary with the same set of keys mapped to boolean values indicating checked/unchecked. –  Marc Cohen Nov 16 '12 at 19:44

If you need simply all checkbox value as checked or unchecked, you can handle its like a ajax call. For this change input type submit to button. Then take all input check boxes checked or not and fill its values into json. Then its value rtrieve your controller post method.

share|improve this answer
:can you please provide me an ajax example code based from the above scenario ?, so that i can learn practically good(i don't know ajax actually :)) –  shiva krishna Mar 13 '13 at 7:18
$("#submit").click(function(){ var curl1_val = $('input[name=curly_1]').is(':checked'); var curl2_val = $('input[name=curly_2]').is(':checked'); var curl3_val = $('input[name=curly_3]').is(':checked'); var curl4_val = $('input[name=curly_4]').is(':checked'); $.ajax({ url: '/checkboxes', type:'POST', data:{action:'checkboxes',curly_1:curl1_val,curly_2:curl2_val,curly_3:curl3_val,‌​curly_4:curl4_val}, success: function(data){ }, error:function(data){ alert("error"+data); } }); }); You should get these value by using web.input(). –  George Varghese Mar 18 '13 at 7:49

Your Answer


