Home > Back-end >  Is it possible to submit a form by triggering Enter with only javascript?
Is it possible to submit a form by triggering Enter with only javascript?

Time:01-05

There ist a Form and Input without a button. You can send a message by typing Enter. The Form has an id.

Is it possible to trigger or kinda faking the Enter-Key only with JavaScript? (No jQuery, because the Page has already loaded).

I tried:

e = jQuery.Event("keypress");
e.which = 13; //choose the one you want
document.querySelector("gui.frm_chat.tabs.tab_6.text.input#main").keypress().trigger(e);

But it didn't have jQuery.

enter image description here

CodePudding user response:

I think form.submit() is what you are looking for: https://www.w3schools.com/jsref/met_form_submit.asp

CodePudding user response:

I guess the better solution is form.requestSubmit(): https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit

  •  Tags:  
  • Related