How to cause radio buttons to auto deselect?

520 views
Skip to first unread message

dlypka

unread,
Nov 26, 2011, 4:00:06 PM11/26/11
to web2py-users
When I create several radio buttons in a web2py form, they do not auto
deselect when another is selected. They all stay selected. Do I need
to add my own javascript code to do the auto deselect (so that only
one radio button at a time stays selected)
or does web2py have some support for this behavior?

chandrakant kumar

unread,
Nov 26, 2011, 4:12:36 PM11/26/11
to web...@googlegroups.com
I think you should group them together, as per common sense, i don't know how to do it.

Anthony

unread,
Nov 26, 2011, 4:25:54 PM11/26/11
to web...@googlegroups.com
Have you tried the radio widget -- SQLFORM.widgets.radio.widget (see http://web2py.com/book/default/chapter/07#Widgets).

Anthony

Matt Gorecki

unread,
Nov 26, 2011, 4:27:33 PM11/26/11
to web...@googlegroups.com
All of the input tags need to have the same name value.

<input type="radio" name="group1" value="Milk"> Milk<br>
<input type="radio" name="group1" value="Butter" checked> Butter<br>
<input type="radio" name="group1" value="Cheese"> Cheese<Br>

Matt

Anthony

unread,
Nov 26, 2011, 4:31:41 PM11/26/11
to web...@googlegroups.com
More generally, if you give all the radio <input> elements the same value for the 'name' attribute, the browser will allow only one to be selected at a time.

Anthony

dlypka

unread,
Nov 26, 2011, 6:08:19 PM11/26/11
to web2py-users
Thanks - I had not noticed that fact hidden underneath the ASP.NET
controls all these years.

Sankhajit Das

unread,
Jan 11, 2017, 11:58:45 PM1/11/17
to web2py-users
i have used @auth.requires_login()  before def index():
which works perfectly,i.e.,first you have to login to give some input..  But i want to save in my database how many people and their information in a database.. How may i do it? Pls help asap
Reply all
Reply to author
Forward
0 new messages