Skip to main content
deckarduk
Inspiring
March 31, 2022
Question

Number of form fields with same name query

  • March 31, 2022
  • 2 replies
  • 2746 views

Hi there,

I've written a script to add checkboxes to a page and the code works ok.

I'm in the process of putting some error handling in however I've hit a slight niggle.

If I use the following to reference a formfield by name is there a quick way to check if there's more than one field with the same name?

thisField = this.getField(theBaseFieldName);

I thought I might be able to check thisField.length to see if it's greater than 1 but unfortunately not. I guessing it's because of the way I'm refering the object. Please can someone point me in the right direction?

Thanks in advance.

This topic has been closed for replies.

2 replies

deckarduk
deckardukAuthor
Inspiring
April 6, 2022

Hi there,

Please can someone point me in the right direction.

The code below doesn't work, or works intermittenly, yet I have verified there is only 1 form field with the name 'ewq'.

var theBaseField = 'ewq';
var thisField = this.getField(theBaseField);
var fieldsNum = thisField.page.length;
//app.alert(fieldsNum)


if (numFields==1) {
    app.alert('Message-1')
} else {
    app.alert('Message-2')
}

If I un-comment app.alert(fieldsNum) I get an undefined error yet the field is there on the page?

Could it be that a persistent session variable is causing the issue?

 

Thanks in advance.

Bernd Alheit
Community Expert
Community Expert
April 6, 2022

You have not set the variable numFields?

deckarduk
deckardukAuthor
Inspiring
April 6, 2022

Thanks Bernd.

I'd been changing variable names, didn't spot that!

Bernd Alheit
Community Expert
Community Expert
March 31, 2022

Check the property page of the field.

deckarduk
deckardukAuthor
Inspiring
April 1, 2022

Hi Bernd,

Thanks for your reply.

 

I'm not sure if I explained things correctly.

All I'm trying to do is find out how many checkboxes there are with the name 'xyz123'.

If the count is greater than 1 then I need to catch that.

Is it a case of looping through all the form fields in the document and check the name of each one?

 

Thanks Bernd

Bernd Alheit
Community Expert
Community Expert
April 1, 2022

Check thisField.page