Skip to main content
1-Visitor
July 16, 2010
Question

javascript help

  • July 16, 2010
  • 11 replies
  • 2889 views

Hi all,

I have a table XUI that I am working on, it is working pretty well. But I now what to add some more functions and they are giving me trouble. I want to remove the rowsep or colsep at the row and entry level. Here is the function I wrote:

function removeSep ( oid, attname )
{
var i,j; // local index variables
var entryChildren;
var oidChildren = oid.childNodes; // the oid passed was the tbody so this give me the rows
for (i=0; i <= oidChildren.length; i++ )
{
Application.alert ("remove seperators for i "+i+attname+" "+oidChildren.item(i).nodeName+" "+oidChildren.length );
oidChildren.item(i).removeAttribute(attname); // all the variables display correctly what I want
entryChildren = oidChildren.item(i).childNodes; // here are the entry children of the row
for (j=0; j <= entryChildren.length; j++)
{
Application.alert ("remove seperators for j "+j+attname+" "+entryChildren.item(j).nodeName+" "+entryChildren.length+" att= "+ entryChildren.item(j).getAttribute(attname)); // displays correct information
entryChildren.item(j).removeAttribute(attname);
} // end for j
Application.alert ("Outside the j loop"); // not getting here -- java exception occurs
} // end for i
}

I turned on the java console to debug, but didn't get any useful information (at least that I could understand). I have also used JSLINT on the internet to check my code syntax and everything checks there.

Any ideas?

Ellen

    11 replies

    1-Visitor
    July 16, 2010

    Addition.....

    I was just looking at the table markup:

    <row valign="middle">
    <entry colname="1" morerows="2" align="left">
    <para><emphasis type="bold">XX</emphasis></para>
    </entry>
    <entry colname="2" morerows="2" align="left">
    <para>YYY.</para>
    </entry>
    </row><row valign="middle">
    <entry></entry></row>

    When I was displaying this table in markup mode, if I had the cursor in the empty cell the function didn't see that I was in a table. All the table functions on the table menu were grayed out. Is that what is causing the java exception?

    Ellen

    18-Opal
    July 17, 2010
    Hi Ellen-



    You don't really say what's going wrong when you run this code, i.e.
    what does it do that's different from what you expect. But I think I can
    guess, because when I run it I get some exceptions.



    The primary thing you need to change is the limits on your loops. You
    have what is known as an off-by-one error. Because arrays are zero-based
    in Javascript, you want the exit condition to be (i <
    oidChildren.length) rather than (i <= oidChildren.length). If you allow
    the index to equal the number of entries, you go one past the end of the
    array, causing the exception. For example, if your array has length=3,
    then the valid indices are going to be array[0], array[1], and array[2].
    If you try to access array[3] it will give an error.



    (In your script this comes up in both loops, so fix it in both places.)



    Once I fixed the off-by-one errors in your loops, everything worked
    correctly, or at least according to my expectations.



    Also, keep in mind that the default is to show row and column separators
    (at least for CALS tables). If they are turned off (by setting the attrs
    to "0"), then this script will turn them back on. And if they are on (by
    not assigning attr values and using the defaults), then the script will
    have no effect even when it's working correctly.



    Finally, when viewing table markup in the document, the table tags are
    treated as regular markup and no longer get special table handling.
    That's why the table toolbar and menu are disabled when you are editing
    a table with view table markup selected. In that view, you have to edit
    the table the same way you would any other markup, e.g. by adding or
    deleting individual elements, using the Modify Attributes dialog, etc.



    --Clay


    1-Visitor
    July 19, 2010

    Thanks Clay,

    I remember changing to <= on one of my tries of doing something and thinking that wasn't quite right, but it seemed to fix something at the time.

    The reason I am doing this code is because I am changing things at the table level, that might have been overwritten by lower level attributes. We have some "standard" table stylesthe users are suppose to use and needed a way to change that style without the user needing to know what all the attribute settings are for the "standard" table style they picked. So yes the code looks strange out of context, but really is what I want to do. 🙂

    Ellen

    1-Visitor
    July 21, 2010

    Hi again,

    My loops are working fine.... BUT now the removeAttribute call sometimes works, but most of the time it causes Arbortext to crash. I can't figure out the rhyme or reason for when it works and when it doesn't. Has anyone else seen something like this?

    Thanks,
    Ellen

    1-Visitor
    July 21, 2010

    I do sometimes get this error message:

    Runtime Error!
    Program: ....epic.exe
    R6025
    - pure virtual function call

    Does that mean anything to anybody?

    In Reply to Ellen Headrick:

    Hi again,

    My loops are working fine.... BUT now the removeAttribute call sometimes works, but most of the time it causes Arbortext to crash. I can't figure out the rhyme or reason for when it works and when it doesn't. Has anyone else seen something like this?

    Thanks,
    Ellen

    1-Visitor
    July 21, 2010
    Sadly, our users have grown to recognized that error as a daily
    reminder to save more often.

    1-Visitor
    July 21, 2010

    I googled (is that a word now?) the error message and it said to uninstall the program and reinstall and it should go away. Well the error message has gone away but nowArbortext just crashes without any message!

    Ellen

    In Reply to Keith Berard:

    Sadly, our users have grown to recognized that error as a daily
    reminder to save more often.

    1-Visitor
    July 21, 2010
    Dear Keith & Ellen,

    Please keep this sort of discussion to a minimum on a public list like this!

    My co-workers keep giving me funny looks when I bust out laughing!


    Thanks anyway - day like today needed it 😉

    John T. Jarrett CDT
    Senior Tech Writer, Integrated Logistics Support, Land & Armaments/Global Tactical Systems

    T 832.673.2147 | M 832.363.7234 | F 832.673.2376 | x1147 | -<">mailto:->
    BAE Systems, 5000 I-10 West, Sealy, Texas USA 77474
    www.baesystems.com
    18-Opal
    July 22, 2010
    Hi Ellen-



    You might try adding some alerts to your code (or write messages to a
    file) to help you get a sense of exactly which operation is causing the
    crash.



    FWIW, the table editor can be touchy. It may not like the way you are
    modifying the data model out from under it. As a quick test, you could
    turn on table tag view (which disables the table editor), then run your
    script and see if it still crashes. If the crashes go away when you have
    table tags turned on, then you know it's the table editor that's
    throwing hissy fits.



    The AOM has a separate, dedicated set of interfaces for dealing with
    table objects: TableObject, TableCell, TableGrid, etc. See the
    Programmer's Reference for details. I wonder if you would have better
    luck making your changes with that approach instead of the standard DOM
    interfaces for modifying nodes and attributes directly. Alternatively,
    you could try temporarily switching to table tag view, doing your
    operation, and then switching back at the end.



    --Clay


    1-Visitor
    July 22, 2010

    Clay,

    Thanks again.

    I had narrowed it down the to the removeAttribute line of code. I just tried your suggestion about turning off the table editor and that worked. I just don't know how to turn off the table editor from within my javascript. I have been looking around the the Arbortext code to see how they do it with the menu choice, but it hasn't made sense to me yet. 🙂

    Ellen



    In Reply to Clay Helberg:

    Hi Ellen-



    You might try adding some alerts to your code (or write messages to a
    file) to help you get a sense of exactly which operation is causing the
    crash.



    FWIW, the table editor can be touchy. It may not like the way you are
    modifying the data model out from under it. As a quick test, you could
    turn on table tag view (which disables the table editor), then run your
    script and see if it still crashes. If the crashes go away when you have
    table tags turned on, then you know it's the table editor that's
    throwing hissy fits.



    The AOM has a separate, dedicated set of interfaces for dealing with
    table objects: TableObject, TableCell, TableGrid, etc. See the
    Programmer's Reference for details. I wonder if you would have better
    luck making your changes with that approach instead of the standard DOM
    interfaces for modifying nodes and attributes directly. Alternatively,
    you could try temporarily switching to table tag view, doing your
    operation, and then switching back at the end.



    --Clay