Having text inputs updated based on another text input change

Hi! I’m having trouble making something work. Basically I want to have multiple text input boxes, where modifying one will also update the others. I’m trying to work a basic example, but I can’t get it to actually update. Here’s what I had so far:

import streamlit as st

st.title("Test")

if "number" not in st.session_state:
    st.session_state.number = 0

if "double" not in st.session_state:
    st.session_state.double = 0

def update_number():
    st.session_state.number = str(int(st.session_state.double) / 2)

def update_double():
    st.session_state.double = str(int(st.session_state.number) * 2)

st.session_state.number = st.text_input(key=1, max_chars=16,
                                        value=0, on_change=update_double)
st.session_state.double = st.text_input(key=2, max_chars=16,
                                        value=0, on_change=update_number)

st.write("Current number:", st.session_state.number)
st.write("Current square:", st.session_state.double)

Hey @jtrudel ,

Welcome to the Streamlit community forum :balloon: :partying_face:

Here’s a similar thread, which might solve your issue :arrow_down_small:

Best,
Avra

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.