• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

how to escape from a javascript procedure.

New Here ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Hi there, i am testing some fileds in an XFA form and into a presign event using Livecycle ES2. I have a code like this:

//Check the Type of Request if selected
if ((F.P1.TypeOfRequest.InitCB.rawValue + F.P1.TypeOfRequest.ModCB.rawValue +         F.P1.TypeOfRequest.DACB.rawValue + F.P1.TypeOfRequest.IDCB.rawValue) == 0) {
 xfa.host.messageBox("The Type of Request is not selected. Please check it.");
 xfa.host.setFocus(F.P1.TypeOfRequest.InitCB); //Fuonziona, anche l'eventuale scroll
 xfa.event.cancelAction = 1;

}


//Check the presence of the UserID when the US Check Box is selected
//if (F.P1.CitizenShip.USCB.rawValue == 1) { 
   if (F.P1.TypeOfRequest.UserID.isNull || (F.P1.TypeOfRequest.UserID.rawValue.length < 10)){
   xfa.host.messageBox("The UserID is not correct or is not filled up. Please check it.");
   xfa.host.setFocus(F.P1.TypeOfRequest.UserID); //Fuonziona, anche l'eventuale scroll
   xfa.event.cancelAction = 1;
}
//}

.

.

.

and so on.

I would like to escape from the presign event once one of the if is true like a goto statement:

//Check the Type of Request if selected
if ((F.P1.TypeOfRequest.InitCB.rawValue + F.P1.TypeOfRequest.ModCB.rawValue +         F.P1.TypeOfRequest.DACB.rawValue + F.P1.TypeOfRequest.IDCB.rawValue) == 0) {
 xfa.host.messageBox("The Type of Request is not selected. Please check it.");
 xfa.host.setFocus(F.P1.TypeOfRequest.InitCB); //Fuonziona, anche l'eventuale scroll
 xfa.event.cancelAction = 1;
// " goto TheEndProcedure " // 
}

Is there the possibility to do that? Thank You.

TOPICS
How to , JavaScript , PDF forms

Views

762

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 23, 2021 Mar 23, 2021

It's pretty simple. Read this: https://www.w3schools.com/js/js_functions.asp

 

Basically you can do it like this:

 

function myFunction() {

// rest of code goes here;

}

myFunction();

 

And when you want to stop the code you add this command into it:

return;

Votes

Translate

Translate
Community Expert ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

This is just standard JavaScript. One way you can do this is with an extra variable:

 

var done = false;

if (firstCondition) {
   // do something
   done = true;
}
else if (secondCondition) {
   // do something else
   done = true;
}

if (!done && thirdCondition) {
   // ... 
   done = true;
}

// and so on

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Put the whole code in a function (could even be an anonymous one) and call return when you want to exit it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

Try67,

i am not so skilled and i do not know how to create my own function.

Please tell me how and where to create a function.  Thank You.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2021 Mar 23, 2021

Copy link to clipboard

Copied

It's pretty simple. Read this: https://www.w3schools.com/js/js_functions.asp

 

Basically you can do it like this:

 

function myFunction() {

// rest of code goes here;

}

myFunction();

 

And when you want to stop the code you add this command into it:

return;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2021 Mar 24, 2021

Copy link to clipboard

Copied

LATEST

Try67,

 

Thank You it works perfect. I want thank also Mr. Karl Heinz Kremer for his solution! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines