Skip to main content
Inspiring
February 7, 2025
Answered

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

  • February 7, 2025
  • 1 reply
  • 447 views

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

Correct answer Nesa Nurani

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.

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
February 7, 2025

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.

Inspiring
February 7, 2025

Many thanks,

 

Works perfectly