Hello,

I want help in python for checkbox form
i use this html code

<input name="do" type="checkbox" value="file1" />
<input name="do" type="checkbox" value="file2" />
<input name="do" type="checkbox" value="file3" />
<input name="do" type="checkbox" value="file4" />

-----------

and after submet

for i in query.getvalue("do"):
    print "_%s_<br>" %(i) 

when i check more than 1 file the loop appear good
file1
file2
file4

If i checked one only appear wrong like
f
i
l
e
3

how can fix this
Thanks

Recommended Answers

You probably have a tuple or a list when you check more than 1 file, and a str or unicode when you check only one file. You could try

val = query.getvalue("do")
if isinstance(val, (str, unicode)):
    val = (val,)
for i in val:
    etc

In python 3, …

Jump to Post

All 2 Replies

You probably have a tuple or a list when you check more than 1 file, and a str or unicode when you check only one file. You could try

val = query.getvalue("do")
if isinstance(val, (str, unicode)):
    val = (val,)
for i in val:
    etc

In python 3, use(bytes, str) instead of (str, unicode).

Thank you very much the peoblem has been solved :)
thanks again for daniweb and your fast responding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.