0

I want all of the following boxes to be filled "excellent":

Screenshot of modules table

let a = document.querySelectorAll('.select2-choice');
   a.forEach((e) => {console.log(e)})
   a.forEach((e) => {e.innerHTML = `   <span class="select2-chosen" id="select2-chosen-410">-Excellent-</span><abbr class="select2-search-choice-close"></abbr>   <span class="select2-arrow" role="presentation"><b role="presentation"></b></span>
`})

I selected their class using querySelectorAll and changed the innerHTML. However, it only changes the pre-written text in the fields but doesn't select the actual options. I just want to fill them with any of their fields, and all at once.

Edric
  • 24,639
  • 13
  • 81
  • 91
solarfire
  • 1
  • 1
  • 3
    It sounds like the webpage you're trying to manipulate uses the jQuery plugin 'select2' to make custom looking select boxes on the page. You probably want to do this https://select2.org/programmatic-control/add-select-clear-items#selecting-options – Andy Ray Jan 31 '23 at 06:13
  • this might help https://stackoverflow.com/questions/10911526/how-do-i-programatically-select-an-html-option-using-javascript – rishi Jan 31 '23 at 06:23
  • @rishi The post you've linked doesn't help, no select elements involved in this question. – Teemu Jan 31 '23 at 06:50

1 Answers1

0

You can try like this and assign the value of the selected item :

const inputs = document.querySelectorAll(".class_name");
for (const input of inputs) {
  input.value = "some text";
}
adiga
  • 34,372
  • 9
  • 61
  • 83
FaFa
  • 358
  • 2
  • 16
  • I doubt that all elements should get the same value. Then it would make no sense to have multiple elements in the first place. – tacoshy Jan 31 '23 at 06:35
  • it was an example. He can can the input of each element according to his needs. – FaFa Jan 31 '23 at 07:02