Skip to main content
Inspiring
Feb 7, 2025 8:51 AM UTC
Answered

javascript tosearch for a form field then hide it or make visible then form field in the loop

Hi there,

 

I am looking for a way of javascript searching and finding the very last visible form field name. 

 

I have 10 buttons named "8 base 2" through to "8 base 10". I need javascript to be able to find the latest visible button and either in the case of the minus button hide the latest one or in the case of the plus button show the next one. I have attached an example of the layout. No scripting added yet.

 

Any help will be greatly appreciated.

 

Kind regards,

 

Steve

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Feb 7, 2025 10:41 AM UTC

For plus button:
for (var i=2; i<=10; i++) {
var f = this.getField("8 base "+i);
if (f.display == display.noView) {
f.display = display.visible;
break;}}


For minus button:
for (var i=10; i>=2; i--) {
var f = this.getField("8 base " + i);
if (f.display == display.visible) {
f.display = display.noView;
break;}}

If you wish to exclude first field set loop to 3.

2 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
Feb 7, 2025 10:41 AM UTC

For plus button:
for (var i=2; i<=10; i++) {
var f = this.getField("8 base "+i);
if (f.display == display.noView) {
f.display = display.visible;
break;}}


For minus button:
for (var i=10; i>=2; i--) {
var f = this.getField("8 base " + i);
if (f.display == display.visible) {
f.display = display.noView;
break;}}

If you wish to exclude first field set loop to 3.

Translate
Inspiring
Feb 7, 2025 10:45 AM UTC

Many thanks,

 

Works perfectly

Translate