Change Form numbers field through dropdown

Hi,
I need to replicate this calculation form but struggle with a numbers field that takes the value when you pic a category from the dropdown.

The tricky part is, that it still should be manually changeable. I feel like, there should be an easy solution, but I just can’t figure it out. I also tried nodes in combination with javaScript but because I am more designer than a developer I am missing some knowledge. :frowning:

I would appreciate some help.

This is where I am at right now. The “Fehltage” should take the value from the “Gewerbe” dropdown. Einsparungsrechner – gesund hoch 2

Thank you for your time,
Morten

I figured it out in the end with Chatgpt. The problem was the ID was applied to the wrapper and not to the form field.

I applied CSS IDs to the number field and the dropdown and used this code with a Code-Element.


  document.addEventListener("DOMContentLoaded", function () {
    setTimeout(function () {
      const gewerbeWrapper = document.getElementById('gewerbeid');
      const fehltageWrapper = document.getElementById('fehltageid');

      if (!gewerbeWrapper || !fehltageWrapper) {
        console.warn("Wrapper divs not found");
        return;
      }

      const gewerbe = gewerbeWrapper.querySelector('select');
      const fehltage = fehltageWrapper.querySelector('input');

      if (!gewerbe || !fehltage) {
        console.warn("Inner input/select not found");
        return;
      }

      // Always update fehltage when dropdown changes
      gewerbe.addEventListener('change', () => {
        fehltage.value = gewerbe.value;
      });
    }, 300); // adjust delay if needed
  });

I’d like to know what kinda prompt wording you used to even get to that solution :laughing:

I begged, I prayed and I insulted. :sweat_smile: Is it a bad solution? Like I sad I am a designer … if it works and looks pretty – I am satisfied. :innocent:

2 Likes