-1

I am trying to write an extension that will search the webpage for a specific text element and write my const into it.

Some additional context: The process flow is essentially;

  1. Pop up prompts user to provide input
  2. User provides input and presses submit
  3. Some changes are made to the input and it is stored as 'data'
  4. Extension then searches webpage for specific text element called 'title'
  5. Extension then writes my 'data' const to this text element.

Here is what I have at the moment - I cannot get this to write. Not sure if it is not identifying the element or not writing correctly.

const titleInput = document.querySelectorAll('input[name="title"], textarea[name="title"]')[0];
if (titleInput.value[0]) {
  titleInput.value = titleWithoutQuotes;
} else {
  console.error('Title input field not found');
}

3
  • Try the deprecated document.execCommand, example. Commented Jul 9, 2023 at 11:55
  • I made you a snippet. Please add relevant HTML Commented Jul 9, 2023 at 12:05
  • if (titleInput && titleInput.value) { Commented Jul 9, 2023 at 12:13

1 Answer 1

0

Your syntax is off

const titleInputs = document
  .querySelectorAll('input[name="title"], textarea[name="title"]'); // get any name=title input or textarea
if (titleInputs.length > 0) {
  titleInputs[0].value = titleWithoutQuotes;
} else {
  console.error('Title input field not found');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the syntax fix. Still no luck, I cannot get this to write. I am specifically trying to write to the Etsy new listing page. I've been at this for like 8 hours and just can't get it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.