0

I'm a new developer trying to make a autofill chrome extension. I manage to retrieve an input from the user but I cannot manage to put that input in the input box on a site. I am trying this on the supreme webshop.

chrome.runtime.onMessage.addListener(gotMessage);

function gotMessage(message, sender, sendResponse) {
  let name = message.txt;
  let nameField = document.getElementsByClassName('order_billing_name');
  nameField.value = name;
  console.log(nameField.value);
  }

I get the correct text in the nameField.value console log but the text does not show up on the site. Can someone help me?

  • 1
    Does this answer your question? [What do querySelectorAll and getElementsBy\* methods return?](https://stackoverflow.com/questions/10693845/what-do-queryselectorall-and-getelementsby-methods-return) – Taplar Aug 25 '20 at 18:38
  • 1
    `getElementsByClassName` does not return a single element – Taplar Aug 25 '20 at 18:38
  • Use `nameField[0].value` instead of just `nameField.value` or `forEach` method in case you have more than 1 element with the `order_billing_name` class name https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach – Ihor Vyspiansky Aug 25 '20 at 18:49
  • See also [Enter data into a custom-handled input field](https://stackoverflow.com/a/57900849) – wOxxOm Aug 25 '20 at 18:49
  • Thank you all for your comments. I’m sorry but I still don’t completely understand. I console logged the getElement to understand more what it actually was. I found out that the get element is the complete div of the html input. Which parameter do I have to change to the text in the html form? Or is this the wrong way of thinking? – MartendeVries Aug 25 '20 at 22:52

0 Answers0