• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit Search
0

Setting up a fillable ranking survey form 1-10 and restricting use of the same number twice

New Here ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

I have a listing of topics with a fillable box for numerical ranking 1-10.   I want to restrict the user from ranking two different topics with the same numerical value.   I've tested the form and I am still able to give all topics the same exact number.   I need to know how to restrict them from using the same number twice.  Thanks! 

TOPICS
PDF forms

Views

593

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

This feature requires scripting. Have you already done something to implement this feature? If so what?

 

But regardless, the first thing to do when designing any kind of interactive feature, and especially a complex feature like you've described, is to create a field naming scheme that naturally organizes the data in the best way for implementing the feature. You'll need this before doing anything else. 

 

These text fields must act together for checking the rank number, so they should be grouped. 

For example, use names like this:  "Rank.Topic1", "Rank.Topic2", "Rank.Topic3", ... "Rank.Topic10"

 

The code for checking rank is basically validating the user entry, so the code is best placed in the custom Validation Script for each field.  The best approach is to write it as a document level function, then the function is called in the individual Validation scripts for each field.    

 

Here's the function:

function ValidateUniqueRankValue()
{
    // First validate the ranking number range
    if((event.value >=1) && (event.value <=10))
    {// Get array of the Rank fields
        var aRandFlds = this.getField("Rank").getArray();
        // Walk field to validate number entry
        for(var i=0;i<aRandFlds.length;i++)
        {
             // Skip current field
             if(aRandFlds[i].name == event.targetName)
               continue;
             else if(aRandFlds[i].value == event.value)
             {  // matching value in other rank field, reject
                 event.rc = false;
                 app.alert("Entered value (" + event.value + ") already in another rank field");
             }
        }
    }
    else
    {// Invalid entry, reject
        event.rc = false;
        app.alert("Entry must be between 1 and 10");
    }
}

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 06, 2022 Dec 06, 2022

Copy link to clipboard

Copied

LATEST

Thank you Thom!  I hadn't done anything with scripting at all.  I think I'm going to create a test document to learn this on as it looks more complicated than what I had anticipated.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines