PDF In-Depth

JavaScript - Binding a variable to the field on a page

February 08, 2000

Advertisement
Advertisement
 

How to get a script to bind a variable to the field on that page only, when you don't know the exact field name in advance.

Question: If I am clicking a button on say, page 26, and there is a field called P26.WORLD.HELLO on that page, how can I get a script to bind a variable to the field on that page only, without knowing the exact field name in advance?

If the button got renamed along with the rest of the fields you can strip off the prefix to the button name (which is stored in event.target.name).


function NamePrefix(cName)
   {
       var cPrefix = "";

       // Grab the index (location, position) of the first ".",

       var nIndex = cName.indexOf(".");

       // Check to see that the index was valid (-1 = it didn't exist)
       if(nIndex!=-1)
       {
               // Use this location of the previous "." as an offset to grab
      the next "."

             nIndex = cName.indexOf(".", nIndex+1);
             //console.println(cName.substring(0,nIndex)); // write to the
      console for debuggin purposes

             // Check to see that the index was valid (-1 = it didn't exist)
             if(nIndex!=-1)
             {

             // Use the location of the second "." with the substring function
      to get
               //   the text up to (not including) the second "."

                  cPrefix = cName.substring(0,nIndex);
            //      console.println(cName.substring(0,nIndex)); // write to
      the console for debuggin purposes
             }
       }
       // return the string to the calling function
       return cPrefix;
}
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.