Mc AbadBoy
Mc AbadBoy

Reputation: 1

How to add the text at the end of the text inside textbox

I got a textbox with name=moderator[custom] and id=moderator-custom, I already have a addon that adds text inside a textbox using custom generators based on name=, it adds text, but the textbox already got random text everytime and I just want to add a text at the end of all that info.

The custom generator that I use to insert the text:

var text1 = faker.random.arrayElement([
           'hello!',
     ]);
return text1; 

How should it look to place the "Hello!" at the end of all te info, keeping the text there too.

Upvotes: 0

Views: 391

Answers (1)

John Lord
John Lord

Reputation: 2175

there are three steps involved in doing what you want.

  1. Retrieve the existing value in the control

  2. Append the new value to the retrieved value

  3. Re-assign it to the control.

    var item = document.getElementById(moderator-custom");
    var text1 = faker.random.arrayElement([
       'hello!',
    ]);
    item.value += text1.value;
    

Upvotes: 1

Related Questions