Distinguish Forms in the Javascript API | Community
Skip to main content
April 21, 2017
Solved

Distinguish Forms in the Javascript API

  • April 21, 2017
  • 1 reply
  • 1572 views

I'm trying to build out some advanced form actions with Javascript that rely on distinguishing between the different forms being interacted with. Unfortunately, I can't figure out the best way to figure which form is which in the native page 2.0 embed. As an example:

<script>

MktoForms2.whenReady(function (form) {

id = form.getId();

if (id = 4529){

alert(id);

}

});

</script>

I would only expect this to send the alert once if one of the forms had an id of 4529. But it will send the alert for every single form so long as one of them has the matching id. Does anyone have some advice on the right way to do this?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

You're missing an equals sign. You want:

if ( id == 4529 ) {

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
April 21, 2017

You're missing an equals sign. You want:

if ( id == 4529 ) {

April 21, 2017

Ugghh. Dumb rookie mistake. Thanks!