SOLVED

Distinguish Forms in the Javascript API

Go to solution
Anonymous
Not applicable

Distinguish Forms in the Javascript API

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?

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Distinguish Forms in the Javascript API

You're missing an equals sign. You want:

if ( id == 4529 ) {

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Distinguish Forms in the Javascript API

You're missing an equals sign. You want:

if ( id == 4529 ) {

View solution in original post

Anonymous
Not applicable

Re: Distinguish Forms in the Javascript API

Ugghh. Dumb rookie mistake. Thanks!