before_next_page and pre-filled radio buttons

129 views
Skip to first unread message

eka...@umich.edu

unread,
May 16, 2022, 12:01:59 PM5/16/22
to oTree help & discussion
I am having an issue with before_next_page and pre-filled radio buttons. 

Essentially, I have a binary choice with the following radio buttons, where we pre-checked one of the two choices in HTML.   However, if the subject clicks next, the choice is recorded as "none" in player variables.  

<input type="radio" name="{{ t.id }}" value="0" checked onclick="sendPref(this)">
<input type="radio" name="{{ t.id }}" value="1" onclick="sendPref(this)">

Is there a way to remedy this?  I.e., have "sendPref" work automatically with the default value that is pre-checked?

Chris @ oTree

unread,
May 17, 2022, 2:23:43 AM5/17/22
to eka...@umich.edu, oTree help & discussion
Does it need to be a live page? How about a regular form field with a radio widget?

If it does need to be a live page, it’s recommended to follow the pattern described here:


On the server, define the current value of the field. Then when the player loads the page, make an empty liveSend that queries which option is currently selected. 

That is better than hard coding in the HTML which option is selected because it works even if the user selects another option then reloads the page. 

Sent from my phone

On May 17, 2022, at 12:02 AM, eka...@umich.edu <eka...@umich.edu> wrote:

I am having an issue with before_next_page and pre-filled radio buttons. 
--
You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/d59ff9b9-dbea-4c60-a14c-76df9e068163n%40googlegroups.com.

eka...@umich.edu

unread,
May 17, 2022, 9:37:20 AM5/17/22
to oTree help & discussion
Thanks, this is helpful!   
Reply all
Reply to author
Forward
0 new messages