Javascript not executing in right order

Avatar

Avatar

Jodi1725

Avatar

Jodi1725

Jodi1725

09-06-2015

Hey my great javascript buddies!!!  Okay So I have the following script on a click event:

var oDoc = event.target

Initial.presence = "hidden"

Printinfo.presence = "visible"

oDoc.mailDoc ({

                         bUI:true,

                         cTo: Name.rawvalue

                         cSubject: Hello

                         });

Why when I click the button does the email send first and then the field hide and become visible.  I need them to hide/visible before the form is emailed. 

What is even more weird is that sometimes it works find and other times it doesn't.  And I can't for the life of me figured out what is wrong!

Any help is always extremely appreciated!

Jodi


Accepted Solutions (0)

Answers (6)

Answers (6)

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

15-02-2018

What about if you just had a separate email button that shows after the 'processing' has been done for hiding the fields? Just means the user will have to click another button, but at least it will do the email when you want.

Avatar

Avatar

Jodi1725

Avatar

Jodi1725

Jodi1725

15-02-2018

Still doesnt work. the only reason for the condition was so that maybe it would prevent the email from happening before hiding the other fields. 

So I removed the conditions and put the newButton.ExecEvent("click') at the end of all the hiding conditions and it still fires before it hides the fields.

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

14-02-2018

Hi Jodi,

I have sometimes also had problems with things not executing in the order i like, so I go about it another way.

What you can try is this:

  • Add a new button that will be Hidden and add the email code to the click event
  • In the button you are clicking above add: newButton.ExecEvent("click"); //this will click the new hidden button programmatically

Because your original button is conditionally sending the email if the emailme variable = 1, you might need to add another condition that will end the code.

For example

if (emailme == 1)

{

newButton.ExecEvent("click"); //this will click the new hidden send email button programmatically

}

if (emailme == 0)

{

end; //end the execution of the code

}

Avatar

Avatar

Jodi1725

Avatar

Jodi1725

Jodi1725

14-02-2018

This is my actual script. (the above was just an example for ease) even when adding semi colons It still emails first and then hides the fields.  I even added the emailme, thinking that it would have to go through those steps first to get to the email me, but still no luck .

if (errorcount == 0)

                {Main.Type.presence = "hidden";

{var tables = Main.GIKDetails.Donor.all;

for (j = 0; j < tables.length; j++)

{if (tables.item(j).NewAdd.rawValue == "0")

{tables.item(j).NewAdd.presence = "hidden"};

if (tables.item(j).ForeignAddress.rawValue == "0")

{tables.item(j).ForeignAddress.presence = "hidden"};

tables.item(j).Spacer6.presence = "hidden";

}};

                {var tables = Main.GIKDetails.Donor.all;

                    for (j = 0; j < tables.length; j++)

                        {var table = tables.item(j);

                         var fund = table.FundInfo.all;

                         for (i = 0; i < fund.length; i++)

                         {var row = fund.item(i)

               

                if (fund.item(i).NewFund.rawValue == "0")

                {fund.item(i).NewFund.presence = "hidden";

                 fund.item(i).NewFundContact.presence = "hidden";

                 fund.item(i).NewFundEmail.presence = "hidden";}

                

           

                fund.item(i).NonGift.presence = "hidden";

                   

                if (fund.item(i).Opportunity.Opportunity2.No.rawValue == "2")

                {fund.item(i).Opportunity.presence = "hidden"};

               

                fund.item(i).Tribute.TributeTxt.presence = "hidden";

                fund.item(i).Tribute.Tribute2.presence = "hidden";

                       

                fund.item(i).AddDesig.presence = "hidden";

                fund.item(i).Spacer3.presence = "hidden";

                fund.item(i).RemoveDesig.presence = "hidden";

                emailme = emailme + 1;

   

       

               

               

                };

                };

                };

};

{if (emailme == 1)

{var oDoc = event.target;

                    oDoc.mailDoc({

            bUI : true,

            cTo : "cashdesk@uif.uillinois.edu",

            cCc : "",

            cSubject : "Gift In Kind - Gift Transmittal",

            cMsg : "",

        })}}

Avatar

Avatar

MinusZero

Avatar

MinusZero

MinusZero

11-02-2018

Hi Jodi,

Some lines of your code are missing semicolons at the end.

Avatar

Avatar

Jodi1725

Avatar

Jodi1725

Jodi1725

09-02-2018

i am still looking for an answer to this question if anyone has any ideas
Thanks!

Jodi