V
Vmusic
Hi,
I am using Javascript to add rows to tables, etc. in a function I am
calling. I pass the function the ID of the div, and what I want in the
rows, and it will add rows to a table in the div.
The problem is I need to test for the existence of the table - and if
the variable or object doesn't exist already my code errors -
PLEASE REMEMBER - I don't know the name of the variable or object I am
testing the existance for - it is created dynamically based on the
divID. So when I test for this object or variable the test has to be
for a dynamically created object -
I tried typeof(eval('frmCntrl_tbl_' + divID) == 'object' //this
fails when the object isn't created yet
Any Ideas Would GREATLY be Appreciated!!
Vmusic
==============code below=======================
//determine if a variable for this div already exists
if(typeof(eval('frmCntrl_tbl_' + divID) == 'object')) //if the object
does not exist this ERRORS
{
alert('A table variable with the divID ' + divID + ' already exists');
}
else
{
alert('First call the to create the table');
//create a table to hold the options or features for this control
//var frmCntrl_tbl = document.createElement('table');
eval('var frmCntrl_tbl_' + divID + ' =
document.createElement(\'table\');');
alert('There is a variable frmCntrl_tbl_' + divID + 'of type: ' +
typeof(eval('var frmCntrl_tbl_' + divID)));
//var frmCntrl_tbody = document.createElement('tbody');
eval('var frmCntrl_tbody_' + divID + ' =
document.createElement(\'tbody\');');
}
I am using Javascript to add rows to tables, etc. in a function I am
calling. I pass the function the ID of the div, and what I want in the
rows, and it will add rows to a table in the div.
The problem is I need to test for the existence of the table - and if
the variable or object doesn't exist already my code errors -
PLEASE REMEMBER - I don't know the name of the variable or object I am
testing the existance for - it is created dynamically based on the
divID. So when I test for this object or variable the test has to be
for a dynamically created object -
I tried typeof(eval('frmCntrl_tbl_' + divID) == 'object' //this
fails when the object isn't created yet
Any Ideas Would GREATLY be Appreciated!!
Vmusic
==============code below=======================
//determine if a variable for this div already exists
if(typeof(eval('frmCntrl_tbl_' + divID) == 'object')) //if the object
does not exist this ERRORS
{
alert('A table variable with the divID ' + divID + ' already exists');
}
else
{
alert('First call the to create the table');
//create a table to hold the options or features for this control
//var frmCntrl_tbl = document.createElement('table');
eval('var frmCntrl_tbl_' + divID + ' =
document.createElement(\'table\');');
alert('There is a variable frmCntrl_tbl_' + divID + 'of type: ' +
typeof(eval('var frmCntrl_tbl_' + divID)));
//var frmCntrl_tbody = document.createElement('tbody');
eval('var frmCntrl_tbody_' + divID + ' =
document.createElement(\'tbody\');');
}