JS on click add text to a input field

Hi,

i want to add a additional text to an input on click.

So i made following code:

document.getElementById("button").addEventListener('click', function () {
    var text = document.getElementById('input');
    text.value += ' Hello';
});

But, when i do it in WeWeb,
First time click = nothing happens
Second time = adds me the text twice
Third time = three times

But when i do it with simple HTML and JS it works.

Is it a bug or i missed something?

you can do this with nocode alone:

  • bind the initial value of the input to a variable
  • on input change (mind not to use on input value change) update the variable to the event value
  • now if you want to add text to the input just change the variable value accordingly

Thanks,
that works perfectly.

I added it to a button, where i say:

Input-Value + " TEXT"

to update the var.

Many many thanks. :+1:

1 Like