JavaScript – Binding a variable to the field on a page

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;
}

You May Also Like

About the Author: Planet PDF Team

Leave a Reply