Copy link to clipboard
Copied
I have stumbled into a nice on OpenPage javascript that automatically set the focus on the first field to be filled. Nice.
if (typeof x == "undefined")
{
var x = 1
var premier = this.getField("T1");
premier.setFocus(); }
But why the if statement to check for var x? What does it do exactly? I can get the same results without it by using only teh last two lines.
Copy link to clipboard
Copied
Hi
This "var x" is useless, and undefined should not have quotes since it's a JavaScript keyword.
if (this.getField("T1") != undefined) {this.getField("T1").setFocus();}
Copy link to clipboard
Copied
What purpose does it give to verify if "T1" is undefined ? Using just this is working.
this.getField("T1").setFocus();
Copy link to clipboard
Copied
Purpose is to avoid to set focus on a field that doesn't exist, because this will thrown a error.
But you can simply use
this.getField("T1").setFocus();
since JavaScript handles this kind of small errors very well.
😉
Copy link to clipboard
Copied
This type of coding is used to only run the block of code within the if statement once. So the first time one opens this page, the field "T1" will receive the focus. The next time that page is navigated to, "T1" will not be focused on.
I usually use this when intializing a form on the first open to run one time only some scripts for filling in dates and setting required starting values.
Copy link to clipboard
Copied