I wrote a function and the definition is as follows
{fn MATCHDATES(var1,var2,var3){
I am able to use var1 and var2 in the function but at the end, I am trying to call the results into a dynamic listbox by putting:
var3 = result
at the end of the function. The dynamic listbox calls the function {MATCHDATES("HPI INFO 1",document.previousdate,document.listbox)}
but it does not work. within the function definition, if all I do is change it to document.listbox=result, the function works. Any ideas why this could be? I need to use the function multiple times within the form with different results so I need to make this work. Thanks,
Could be a couple of issues.
1) Using document variables inside functions can produce unreliable results unless they are declared as global values. If using VFE, check the 'Make available to other forms' check box and ensure they are uniquely name to prevent collisions.
2) When assigning a value from a function, you have two options:
- Direct assignment, which you found already works but really should be reserved for global variable assignment as it has limited application otherwise
- Use the function to return the value to the variable via the ‘return’ statement.
i. i.e. return result
ii. To accomplish this, you need to assign the returned result to Var3 during the function call itself (outside of the function).
- DOCUMENT.VAR3 = MATCHDATES(var1,var2)
iii. Using this approach, you maximize the utility of the function.
Thank you so much. This worked perfectly