Submit Server Connect Form via Javascript

Hi.
I have a server connect form which POSTs values to a server action.
But I need to submit the form from JS.
Doing something like document.getElementById("form1").submit(); redirects the page to the action of form - which is the default HTML Form behaviour.

Is there any way I can invoke App Connect’s form1.submit() from JS?

Why do you need to use JS to submit Server Connect form? Anyway…

This is not official method, but you can use javascript to trigger ‘click’ the server connect submit button. You can hide the server connect submit button if you don’t want it to be visible.

Thanks for the solution. Should have thought of clicking the button instead of submitting the form. :sweat_smile:

The reason why I need this is because I am using a 3rd party JS tool which returns values via JS events. And I need to transfer these values to server action without user intervention.
So I have created a server connect form on the page with hidden fields, which I can now submit by invoking the submit button’s click event.

Following on from this, I have some custom javascript which I want to call a Server Connect element to send out an email. Can someone help me with the best technique for this?

you are looking to call a ServerConnect from a customer JS, right?

from your custom JS, call this:
dmx.parse('serverConnectName.load()')

and if it is in an SPA page, then:
dmx.parse('routeName.serverConnectName.load()')

also, if you have any collapse/conditional regions, then the parse text will have to be changed accordingly.

also, you may give the params for the server connect like this:
load({param1: 'value1', param2: dynamicValueFromVariable})

Wow, that’s an excellent set of code which I will put in my notes as this is bound to be very useful in future projects. Many thanks.

super.

another tip: dmx.parse works in browser console - very helpful to debug and test.

2 Likes