0

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.

3
  • 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?
    – leymannx
    Commented Oct 7, 2022 at 7:49
  • 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. Commented Oct 7, 2022 at 9:48
  • 1
    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();
    – Beebee
    Commented Oct 7, 2022 at 11:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.