cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Finding the Table OID

ebheadrick
1-Newbie

Finding the Table OID

Hi All,

I have a dialog box that I display when a user is inside a table and selects the menu option that I added. What I am stump on now is how I get the oid of the table so that I can then set attributes on the table tag depending on the option selected in the dialog.

Here is the javascript function I am trying to write, maybe javascript is not the best option for this so if you have other solutions I will take them into consideration also.

function getTableid()
{
var table_oid=0;
var caretCellId = Acl.eval("tbl_oid_cell(oid_caret())");
Acl.eval("tbl_obj_attr_get( caretCellId, 'OID', table_oid )");

Application.alert("inside get Table id "+caretCellId +"-"+table_oid);

return table_oid;
}

I am getting a numberfor the caretCellId, but the table_oid is always 0.

Thanks,
Ellen

3 REPLIES 3

Hi Ellen-



Try using the document.insertionPoint to get the insertion point (as a
DOM Range), then use startContainer to get the oid containing it. From
there you can walk up the tree until you find the table element. It
would look something like this:



var doc=Application.activeDocument;

var cursor = doc.insertionPoint;

var node = cursor.startContainer;

// probably also want to add a test in the while loop to make sure you
don't go off the

// top of the document if for some reason the cursor wasn't in a table

while (node.nodeName != "table" && node.nodeName != "informaltable") {

node = node.parentNode;

}

node.setAttribute("role","test");



HTH



--Clay


Thanks Clay,

After I sent the messageI wondered if that was the wayI should go 🙂

I will get busy on this option.

Ellen

Hi Ellen,

I'm not sure if this is helpful as it's pure ACL, but here's a similar
function I wrote last year. It returns the table OID whether a table is
actually selected, or if the cursor is within a table it selects the
nearest table element.

function select_table() {
local $found = 0;
local $oid;

# is a table element already selected?
$oid = selected_element();
if($oid != oid_null() && oid_type($oid) == 0 && oid_name($oid) ==
"table") {
$found = 1;
}

if(!$found) {
# no table selected, so determine if the cursor is within a table, by
# searching "up" the document object tree for a <table> element
$oid = oid_caret();

while($oid != oid_null()) {
if(oid_type($oid) == 0 && oid_name($oid) == "table") {
$found = 1;
break;
} else {
$oid = oid_parent($oid);
}
}
}

return $found ? $oid : oid_null();
}

Cheers,
Gareth

Announcements

Top Tags