Score:0

Submit webform via custom button

cn flag

I want to update a webform submission via custom button.

On the same page as my webform I created a custom button in a block.

 <button id="myButton" onClick="submitWebform()" type="submit"> Click here!  </button>

with JS code

 function submitWebform() {
       document.getElementbyId("webform-submission-id").submit();
 }

But when I click on the button the page reloads but my webform is not sent.

What to do ?

My goal is to update fields with query parameters by clicking the button.

leymannx avatar
ne flag
I think this function never gets triggered. Just the button behavior kicking in. Where exactly you placed the JS? Where exactly you placed the button?
Monster97139 avatar
cn flag
I placed the JS with the Asset Injector module. The button is in the left sidebar and my webform is in the main content. I think the function is called because when I do: function submitWebform() { document.getElementById("edit-actions-submit").click(); } The webform is submit.
Beebee avatar
sa flag
Try to change the button type to `type="button"` which would perhaps stop it acting as a submitter of its own form. Either that or receive `event` parameter in the js function like `submitWebform(event)` and call `event.preventDefault();`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.