Skip to main content
deckarduk
Inspiring
Mar 31, 2022 3:28 PM UTC
Question

Number of form fields with same name query

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 is closed to new replies. Start a new post to keep the conversation going.

24 replies

deckarduk
deckardukAuthor
Inspiring
Apr 6, 2022 10:42 AM UTC

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.

Translate
Bernd Alheit
Community Expert
Community Expert
Apr 6, 2022 11:37 AM UTC

You have not set the variable numFields?

Translate
deckarduk
deckardukAuthor
Inspiring
Apr 6, 2022 11:55 AM UTC

Thanks Bernd.

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

Translate
Bernd Alheit
Community Expert
Community Expert
Mar 31, 2022 3:48 PM UTC

Check the property page of the field.

Translate
deckarduk
deckardukAuthor
Inspiring
Apr 1, 2022 7:59 AM UTC

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

Translate
Bernd Alheit
Community Expert
Community Expert
Apr 1, 2022 8:16 AM UTC

Check thisField.page

Translate