Skip to main content
Josh_Lauder
Participating Frequently
April 15, 2018
Question

Making field visible based on OnFocus event of another field

  • April 15, 2018
  • 2 replies
  • 1198 views

Hi, I have a text field called “customerBName” which by default is always visible  and another two fields called “customerBAddress“ & “customerBTel” which by default are hidden.

I need a script for the On Focus event on

”customerBName” which will do the following:

When the user clicks (or tabs)  into “customerBName” then the fields “customerBAddress” & “customerBTel” become visible(but not printable).

If the user then enters data in ”customerBName” and subsequently tabs out then the other two fields remain visible(but not printable).

However, if no data was entered in “customerBName and the user tabs out then the other two fields revert back to their original hidden state.

This topic has been closed for replies.

2 replies

Josh_Lauder
Participating Frequently
April 15, 2018

Sorry, I meant customerBName

try67
Community Expert
Community Expert
April 15, 2018

Yeah, it seems to cause some confusion in the tab order... This solution worked for me, though.

In the first part of the On Blur script add the following command:

this.getField("Name of next field in the tab order").setFocus();

Josh_Lauder
Participating Frequently
April 16, 2018

Is there any way to differentiate an On Blur event between a user tabbing to the next field and a user clicking with the mouse in to another field?

Because the tabbing order is obviously meant to be set if the user is using the tab button to tab over in order to make it easier to fill out a form. However, the user should still be able to click in to any field with the mouse if they so choose.

This script forces the focus on the next field in the tab order - even though the user clicks with the mouse in to a different field that is not in the tab order it still puts the focus back in to the field that your forcing the focus on.

try67
Community Expert
Community Expert
April 15, 2018

On Focus script:

this.getField("customerBAddress").display = display.noPrint;

this.getField("customerBTel").display = display.noPrint;

On Blur script:

if (event.target.value=="") {

    this.getField("customerBAddress").display = display.hidden;

    this.getField("customerBTel").display = display.hidden;

} else {

    this.getField("customerBAddress").display = display.noPrint;

    this.getField("customerBTel").display = display.noPrint;

}

Josh_Lauder
Participating Frequently
April 15, 2018

The code works pretty much the way it's supposed to, however, if no data is entered in customerName2 and I tab over it doesn't continue on to the next visible field in the tab order. It restarts the tab order from the beginning of the document.