Skip to main content
ExLibris
  • Subscribe by RSS
  • Ex Libris Knowledge Center

    Using placeholder variables in javascript

    • Article Type: General
    • Product: Aleph
    • Product Version: 18.01

    Description:
    We would like to use some of the placeholder variables (e.g. $0100, $0200) in javascript functions. Simple assignments don't seem to be working reliably. Has anyone hit on a technique for using those variables in javascript?

    Resolution:
    The technique we're using is to put the variable, by itself, inside an HTML element (like a "<div>") that has a unique ID, and then reference the ".innerHTML" property of the element in order to use the value in javascript. E.g.:
    ----------
    <div id="divHOL1">
    $0100
    </div>
    <script type="text/javascript">
    sVar = document.getElementById("divHOL1").innerHTML;
    </script>
    ---------
    This avoids the problem of javascript seeing single/double quotation marks inside the Aleph variable and chopping off the string.

    In practice, we also usually have to use javascript to output the HTML element itself, because re-using an "id" tag (on screens where the same Aleph variable gets output multiple times with different values, which is a lot of screens) will cause the "getElementById" function to fail in Internet Explorer (works in Firefox).

    So, the example above becomes (where the "iHolIdx" variable has been initialized and incremented elsewhere):
    ---------
    <script text="text/javascript">
    document.write('<div ID="divHOL'+iHolIdx+'">');
    </script>
    $0100
    </div>
    <script text="text/javascript">
    sVar = document.getElementById("divHOL"+iHolIdx).innerHTML;
    </script>
    ---------

    Thanks to Kerry Bouchard, Texas Christian University for posting this information to the ELUNA-PUB-INTERFACE-IG-L list.


    • Article last edited: 10/8/2013
    • Was this article helpful?