I need to use JavaScript to update some data in a input field, and then programmatically to simulate a "Enter" keypress in order to fire up some events of that field to validate data.
Note that I didn't develop the site. I just do some add-on script for some customization. Therefore, I don't know what exact events attached to that field, or to be fired. All I know is if I do it manually, after key in item# and press enter, it will do something for validation.
I searched result here before. I have tried following 3 methods and all failed.
Any more ideas on how to solve?
#1:
const kexx = new KeyboardEvent('keypress', {
bubbles: true, cancelable: true, keyCode: 13
});
inputEle.dispatchEvent(kexx);
#2:
var exx = jQuery.Event("keypress");
exx.which = 13; //choose the one you want
exx.keyCode = 13;
$(inputEle).trigger(exx);
#3:
$(inputEle).val(itemnbrInputAry[i]).trigger('keyup');