Search code examples
javascriptinputtextbox

Make user change value of Javascript


I have a problem where i want to let the user input their name in a text field and make that change a value in javascript

`

Splain.addEntry({
  people:{
    all:["{{THISNEEDSINPUT}}"],
},

How can i make this possible?


Solution

  • You can do the following :

    <input id="name-input" />
    
    const obj = {
      people: {
        all: [ "{{THISNEEDSINPUT}}" ]
      }
    }
    
    window.onload = () => {
      const input = document.getElementById('name-input')
    
      input.onkeydown = () => {
        obj.people.all[0] = input.value
      }
    }
    
    Splain.addEntry(obj)