oTree Forum >

Snippet radio_switching_point don't go to next page

#1 by Susan

Hi Chris,

I tried the following code of snippet radio_switching_point in otree studio. However, when I click the next button, it did not submit the data, nor did it goes to the next page.

I found that this was a bug and you have fixed it according to https://groups.google.com/g/otree/c/hcnSRTKtb3c
So I am confused why it doesn't work well for me.

The code:

<input type="hidden" name="switching_point">
{{ formfield_errors 'switching_point' }}

<table class="table table-striped">
        <col width="45%">
        <col width="10%">
        <col width="45%">
        <td align="right"><b>Option A</b></td>
        <td align="left"><b>Option B</b></td>
    {{ for amount in right_side_amounts }}
        <td align="right">
            <b>{{ player.left_side_amount }}</b> now
        <td align="middle">
            <input type="radio"
                   name="{{ amount }}"
            <input type="radio"
                   name="{{ amount }}"
                   value="right" data-amount="{{ amount }}"
        <td align="left">
            <b>{{ amount }} </b> next month
    {{ endfor }}

<button type="button" class="btn btn-primary" onclick="submitForm()">Next</button>

    let allRadios = document.querySelectorAll('input[type=radio]')
    function submitForm() {
        let form = document.getElementById('form');
        if (form.reportValidity()) {
            let allChoicesAreOnLeft = true;
            for (let radio of allRadios) {
                if (radio.value === 'right' && radio.checked) {
                    forminputs.switching_point.value = radio.dataset.amount;
                    allChoicesAreOnLeft = false;
            if (allChoicesAreOnLeft) {
                // '9999' represents the valueInput if the user didn't click the right side for any choice
                // it means their switching point is off the scale. you can change 9999 to some other valueInput
                // that is larger than any right-hand-side choice.
                forminputs.switching_point.value = '9999';

    function onRadioClick(evt) {
        let clickedRadio = evt.target;
        let afterClickedRadio = false;
        let clickedRightRadio = clickedRadio.value === 'right';

        for (let aRadio of allRadios) {
            if (aRadio === clickedRadio) {
                afterClickedRadio = true;
            if (clickedRightRadio && afterClickedRadio && aRadio.value === 'right') {
                aRadio.checked = true;
            if (!clickedRightRadio && !afterClickedRadio && aRadio.value === 'left') {
                aRadio.checked = true;

    document.addEventListener("DOMContentLoaded", function (event) {
        for (let radio of document.querySelectorAll('input[type=radio]')) {
            radio.onchange = onRadioClick;


#2 by BonnEconLab

I just tested the code (locally, not using oTree Studio) with oTree v5.10.3 and up-to-date Chrome, Edge, Firefox, and Safari browsers. The code works perfectly fine, which includes recording the value for switching_point correctly and advancing to the next page.

If you do a right click on one of the elements (say, the “Next” button) and choose “Inspect,” do you observe any JavaScript errors when clicking the “Next” button?

#3 by Susan

Thank you for your help. The error is:
Uncaught ReferenceError: forminputs is not defined
    at submitForm (6:250:21)
    at HTMLButtonElement.onclick (6:240:70)
Even when I run the radio_switching_point snippet of the downloaded otree-snippets.otreezip, the same error occurs.

#4 by Chris_oTree

Upgrade oTree. forminputs doesn’t work in old otree versions.

#5 by Susan

Thank you. I used the command pip3 install -U otree to upgrage otree, the screenshot is attached below. However, the "next" button still didn't work.
According to the screenshot, it seems that my otree version is still not the latest, right? How can I get the latest version?

Write a reply

Set forum username