Home > database >  How to auto use an enter event after I change the value of an input with javascript?
How to auto use an enter event after I change the value of an input with javascript?

Time:01-23

I will change the value of an input field with this in the console:

document.getElementById("repository-path").value = "/content/*/americas/us/en/";

and when the value has changed, it should direct me to the page in the CMS tree.

But without pressing enter it doesn't open the tree.

So I'm wondering if I can fire an enter keyboard event with vanilla javascript so that without pressing enter the input value should open automatically.

I tried this :

var evt = new KeyboardEvent("keydown", { bubbles: true, cancelable: true, keyCode: 13 }); element.dispatchEvent(evt);

but it didn't work for me.

I'm not good with programming, just want to optimize content editing time for myself.

Thanks.

CodePudding user response:

you can simulate the keypress in javascript:

const event = new KeyboardEvent('keydown', {'keyCode':13, 'which':13});
input.dispatchEvent(event);
  • Related