A website is displaying a lot of items in a table. The table changes as I type into the searchbar at the top, which acts as a filter. This should be automated (client-sided).
I created a Chrome extension to run the script.
The problem:
My script is able to set the searchbar's value to the string that i want it to be using:
document.getElementById('filter').value = "Apple";
The problem is, that the table below is not being updated even though the text inside the searchbar is displaying "apples". If i remove a letter by hand, it instantly updates and filters the results.
Is there any way to "simulate" actual keypresses so the table gets updated?
Edit and almost solution:
I have been trying so hard to make this work and failed every single time. Then I started to learn a bit of jquery and came over this. A single line of code.
$("#filter").val("apple").trigger('keyup');
Works perfectly fine.
I still thank you a lot, marcelino! You've been a big help and you tried so hard to solve my problem with me! Thank you!
Edit_2 and final solution:
The first "solution" didn't work when using it in a chrome extension. This solution works perfectly fine. It changes the value and then fires an ArrowUp event to trigger the filter.
var filter = document.getElementById("filter");
filter.value = "apple";
filter.dispatchEvent(new KeyboardEvent("keyup", {
bubbles: true,
cancelable: true,
key: "ArrowUp"
}));
Solved here: Different results between chrome console and extension