oTree Forum >

Make field blank for re-use

#1 by gonarr,

Hi, my app has 1 round, yet I am using the same page multiple times. The fields in this page (multiple choice questions) are hence also used multiple times. However, the response given to the first appearance of the page is set as a default response for the second page appearance. Would anyone know how to make these be blank again?

Many thanks

#2 by mlt_123,

"In recent versions of oTree, you can access your form field inputs through the JavaScript variable "formInputs". More details here: https://otree.readthedocs.io/en/latest/forms.html#javascript-access-to-form-inputs

This is an easier way than the previous approaches.

Old way:
let myInput = document.querySelector('[name=xyz]')

New way:
let myInput = formInputs.xyz

Another benefit of this new feature is that it makes it easy to work with radio buttons, which is typically complicated to do with JavaScript (since each radio button is actually a separate <input>). 

Now you can do it the intuitive way, as with any other input:

let myValue = formInputs.rate.value;


formInputs.xyz.value = 10

And that will automatically check the appropriate radio button."

Copied from the otree google Groups.
I'd suggest you combine that feature with some basic javascript.

#3 by gonarr,

Thank you for the response!

I will try this. I could not, however, find anything about "formInputs" in the link you mention. It seems there the way to access is as follows:
<input type="hidden" name="contribution" id="contribution" />

# JavaScript
document.getElementById('contribution').value = 42;

Would you know where I can find details ofr the "formInputs" syntax?

Thanks again

#4 by Chris_oTree,

Yes I added formInputs recently, but temporarily removed it from the documentation because I want to add some refinements to the way it works.

#5 by Chris_oTree,

Anyway why not use multiple rounds?

Write a reply

Set forum username