Remove embedded blanks in LANSA HTML field names

Date:Archived
Product/Release:LANSA for the Web
Abstract:Some JavaScripts which overcome the problem of embedded blanks in LANSA HTML field names
Submitted By:Alan Seiden (Strategic Business Systems)

Here are some JavaScripts which overcomes the problem of embedded blanks in LANSA HTML field names.

1. IsDropDown is used by SetFieldValue (see next line).

2. SetFieldValue changes the value of a field. Pass in the name of the field and the value.

3. GetFieldValue is used to READ the value of a field.

Here are the scripts:

function IsDropDown(obj)
{
    // Returns true if the object is a SELECT (drop-down) object
    //
    // By Alan Seiden, Strategic Business Systems, Inc., 1999; aseiden@sbsusa.com
    //
    var TheType = obj.value;
    if (TheType == null) // no regular value if a SELECT object.
        ItIs = true;
    else
        ItIs = false;
    return ItIs; // Return the verdict. True means it is a drop-down
 (select) object.
}

function SetFieldValue(FieldName, NewValue)
{
    // Set the value of a field even if the field name has embedded blanks.
    //
    // By Alan Seiden, Strategic Business Systems, Inc., 1999;
    //
    var NumElements=document.LANSA.elements.length;
    for (i=0; i<NumElements;i++) // go through all the elements till we
		 find the right one.
    {
        var obj = document.LANSA.elements[i];
        if (obj.name==FieldName) // we found it.
        {
            if (IsDropDown(obj) == false) // not a drop down, but a 
		regular input field.
            {
                obj.value=NewValue;
                break; // we're done.
            }
            else
            {
                // A drop down; go through items in dropdown till we find a match.
                var NumItems = obj.length
                for (j=0; j<NumItems;j++)
                {
                    if (obj.options[j].value == NewValue) // item matches our value.
                    {
                        obj.selectedIndex = j; // make this one "selected."
                        break; // we're done.
                    }
                }
            }
        }
    }
}

function GetFieldValue(FieldName)
{
    // Get the value of a field even if the field name has embedded blanks.
    //
    // By Alan Seiden, Strategic Business Systems, Inc., 1999;
   //
    var NumElements=document.LANSA.elements.length;
    var TheValue='';
    for (i=0; i<NumElements;i++) // go through all the elements till we
		 find the right one.
    {
        var obj = document.LANSA.elements[i];
        if (obj.name==FieldName) // we found it.
        {
            // it's the right field.
            if (IsDropDown(obj) == false) // not a drop down, but a regular
		 input field.
                TheValue = obj.value;
            else
                TheValue = obj.options[obj.selectedIndex].value;
                break;
        }
    }
    return TheValue;
}