Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How do I find form name?

Avatar

Level 2

Hello,

Trying to figure out the form name, but not getting desired result with the following:

if (xfa.form.name == "form050") then

.
.
.
Any suggestions?  Thanks.
-Veni

1 Accepted Solution

Avatar

Correct answer by
Level 4
Level 4

Your code fails because of "then", which isn't javascript.

I.e. the line fails silently, which I find quite odd. If not an exception, the js engine should at least generate a syntax error. What happens is that it simply continues execution.

This produces the same behaviour:

if (false) askldalksdjhaldh
{ app.alert("you should never see this message."); }

This produces an error (as it should):

if (false) askldalksdjhaldh { app.alert("you should never see this message."); }

View solution in original post

0 Replies

Avatar

Level 10

One way is to add the name of the form as the title in the form properties. You can then reference "xfa.host.title".

Untitled.png

Steve

Avatar

Level 2

Thanks for the suggestion, but my if statement still fails to execute properly after I changed my form properties to:

FL-335 Properties.png

and changed my code to:

if (xfa.host.title == "MC-050") then

{

xfa.host.messageBox("In == mc050, UPPERcase p section ALNvali.","Error"); // vh

What happens is that the comparison I make (above), even though the title does NOT equal MC-050, determines the title to be equal and I get my message to pop up.  Just to test, I added the following to verify the title:

xfa.host.messageBox(xfa.host.title,"Error"); // vh

and it did in fact yield:
FL-335 Properties Test.png
So I'm not sure why the comparison isn't working properly.  Thanks for your help.
-Veni

Avatar

Level 10

This works for me....

// form1.page1.btn::click - (JavaScript, client)


if (xfa.host.title == "HowTheHeck.pdf") {

  xfa.host.messageBox(xfa.host.title);

}

else {

  xfa.host.messageBox("Not HowTheHeck.pdf");

}

Steve

Avatar

Level 2

What if you switch your comparison value after the == to say, "Form.pdf" or some value not equal to what your form title is?  I ran into this because initially my test was just like yours where I had the "nice" or expected comparison that should work, but then I found out that my 'else' portion was never being accessed because the first equality comparison was somehow ALWAYS true.  Thanks.

Avatar

Correct answer by
Level 4
Level 4

Your code fails because of "then", which isn't javascript.

I.e. the line fails silently, which I find quite odd. If not an exception, the js engine should at least generate a syntax error. What happens is that it simply continues execution.

This produces the same behaviour:

if (false) askldalksdjhaldh
{ app.alert("you should never see this message."); }

This produces an error (as it should):

if (false) askldalksdjhaldh { app.alert("you should never see this message."); }

Avatar

Level 2

Oh no!  That means I got a lot of code to go through and fix....not good!  >:-<

I really wish they'd address this -- I can't imagine being the only one that's ran into this "silent fail" issue with SmartForms and JavaScript.

I'll change my code and see if it all works now. 

Thanks for the tip!!!