Expand my Community achievements bar.

Add a change event to prompt a function return different result

Avatar

Former Community Member

I have a change event in a drop down list, DDL_1, that calls a function from my variables. This DDL_1 returns a value to a text box, Text_1, that I use to calculate time. Inside this change event in DDL_1 I have a conditional statement that is based on user input from a date field, Date_1.

My issue is that I need the text box to update/change when I change the value in Date_1 and not just in the DDL_1. I can get the proper value if I change Date_1 and then choose a different value in DDL_1 and select the initial value again, but I'd like the data in Text_1 to automatically change whenever either fields are changed. I suspect there is some capability with the change event of Date_1 but I thought maybe there was a very simple command I could insert and wanted to go to the experts for best practice.

The code in the change event of DDL_1 follows this psuedo-code format:

if(Date_1 > somedate && Date_1 < someotherdate){

execute function with certain data

}

else{

execute function with different data

}

6 Replies

Avatar

Level 7

Why don't you put that code in the layoutReady event instead of the change event and just add an extra if condition that the dropdown list == whatever.

Avatar

Former Community Member

Could you explain this concept a little further? I am not familiar with the layoutReady event.

Avatar

Level 10

Hi,

I wouldn't go down the layout:ready event route as overusing this event in a form can lead to performance issues. See here: http://assure.ly/nB0Bvz.

Instead why not have the script in the calculate event of the textfield? This way when ever the date or dropdown are changes the calculate event in the textfield will fire.

Hope that helps,

Niall

Avatar

Level 8

I'd put your script in the calculate event of Text_1.

Avatar

Former Community Member

Well that is not exactly an easy option based on my set up currently. I guess I could use it as a last resort but there is no command or event that would just simply cause it to update if a certain field was changed? Or maybe make the date field change the DDL field which in turn would change the other field?

if(date_field changes){

reset my value}

I am not that experienced with livecycle so this could be impossible, I just thought there'd be an easier way that I am not aware of. I tried to put the script in the calculate field but then ran into 5 more problems. 

EDIT: and to explain my issue a little further, I actually believe I'm using adapted code that come from one of your previous posts Niall (or possibly one of the other more prominent members of this forum) that assigns values to items in the DDL from arrays in global variables. I'm doing this because many different variables share the same bound value. The reason I can't remove it from my change event is it sends the value of the variable to this text box by taking the value of the entered variable. Hopefully that helps enlighten the problem.

Avatar

Level 10

Hi,

It could be from an example, but without seeing the form/script it is difficult to say.

I would still recommend the calculate event of the textfield as the best option.

Where you have script in the change event of the dropdown, you would also need to add script into the exit event of the date field. This would reset the value of the textfield when the user exits. However this will not give as good a user experience, depending on the sequence the user follows when compling the form.

Maybe if you could share your form. If you can upload it to a file sharing site; publish it; and then post the published URL here.

Niall