Re: Radio Buttons Random Order

28 views
Skip to first unread message

villas

unread,
Jun 12, 2013, 5:15:46 PM6/12/13
to web...@googlegroups.com
I wonder whether you could do something like this:

input random
answers
= range(1,5)
random
.shuffle(answers)
inputlist
= CAT()
for a in answers:
    inputlist
.append(TR(x['answer{0}'.format(a)],INPUT(_type="radio", _name="operation", _value='answer{0}'.format(a))))
form
= FORM(TABLE(inputlist))



Austin Nisenbaum

unread,
Jun 12, 2013, 6:44:53 PM6/12/13
to web...@googlegroups.com
Hmm unfortunately that didn't work, I appreciate the help though!

Anthony

unread,
Jun 12, 2013, 10:59:23 PM6/12/13
to web...@googlegroups.com
How about something like:

import random
rows
= random.shuffle([TR(x.answer1,INPUT(_type="radio", _name="operation", _value="answer1")),
                       TR
(x.answer2,INPUT(_type="radio", _name="operation", _value="answer2")),
                       TR
(x.answer3,INPUT(_type="radio", _name="operation", _value="answer3")),
                       TR
(x.answer4,INPUT(_type="radio", _name="operation", _value="answer4"))])
rows
.append(TR("",INPUT(_type="submit", _name="submit", _value="Submit")))
form
= FORM(TABLE(rows))

Anthony

On Wednesday, June 12, 2013 2:38:31 PM UTC-4, Austin Nisenbaum wrote:
Using Web2py, in the default controller, how can I randomize the order that the radio buttons appear on the screen? Ex: I don't want answer1 to appear before all of the other radio buttons all of the time.

def index():
    import random
    recaptcha_row = db(db.recaptcha_qa).select(orderby="<random>")
    for x in recaptcha_row:
        statement=x.statement
        question=x.question    
        
        form = FORM(
                
                TR(x.answer1,INPUT(_type="radio", _name="operation", _value="answer1")),
                TR(x.answer2,INPUT(_type="radio", _name="operation", _value="answer2")),
                TR(x.answer3,INPUT(_type="radio", _name="operation", _value="answer3")),
                TR(x.answer4,INPUT(_type="radio", _name="operation", _value="answer4")),
                TR("",INPUT(_type="submit", _name="submit", _value="Submit")),
   
                   )
       
        if form.accepts(request.vars,session):
           
           if (form.vars.operation=="answer1"):
                   
                   redirect(URL("right_answer"))
               
           else:
                   
                   redirect(URL("wrong_answer"))
               
    return dict(statement=statement,question=question,form=form)

def right_answer():
    
    return dict()
    
def wrong_answer():

    return dict()

Reply all
Reply to author
Forward
0 new messages