|
-
September 3rd, 2008, 02:09 AM
#1
Executing script inside a dynamicaly created table cell
Hello gurus,
My objective is to execute a function when a row is added to a table.
The row addition is done dynamicaly using JS
to do this. i dynamicaly create a table cell and embed a <script> tag inside ( as innerHTML) .
Code:
"<scr"+"ipt language='javascript'> alert( 'hello'); " + "</scr"+"ipt>"
i expect to see an alert each time the cell was added.
but nothing showed up. what could be the problem?
btw i cannot write
Code:
"<script language='javascript'> alert( 'hello'); </script> "
because the </script> tag inside the string causes conflict with the actual <script> opening tag.
Thanks in advance
Last edited by akgalp; September 3rd, 2008 at 02:11 AM.
-
September 3rd, 2008, 08:31 AM
#2
Re: Executing script inside a dynamicaly created table cell
JavaScript cannot be used to write JavaScript. Instead, when you create the cells, you simply attach the event with its function.
Code:
var td = document.createElement('td');
td.onclick = function;
tr.appendChild(td);
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 3rd, 2008, 10:47 PM
#3
Re: Executing script inside a dynamicaly created table cell
Thanks for the response.
But, no there won't be any user interaction with the cell.
I'll try to explain more.
First, this is not a web appln, rather it would be an hta.
i'm creating table rows dynamically (it will depend on some file content etc)
now each row has a column that displays a timeout field ( a countdown time ), so after the timeout, the filed ( or row ) will be deleted.
so i'm thinking of starting a timer when the row is created( each row will have its own timer - any limitation? ). and i planned to execute a script when the row is created. and this is not working as expected.
-
September 4th, 2008, 06:54 AM
#4
Re: Executing script inside a dynamicaly created table cell
You can create timers dynamically which can call a function also created dynamically.
Code:
var timers = [];
...
timers[timers.length] = setTimeout(function() {
// now remove the table row
}, 10000);
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
September 5th, 2008, 08:37 AM
#5
Re: Executing script inside a dynamicaly created table cell
hmm.. well that was good..
well i tried in another method .. seems to work, but now another problem
Code:
function DeleteExpiredRows()
{
var table = document.getElementById("Study_List");
for( i=0; i< table.rows.length; i++)
{
if( typeof(table.rows[i].timestamp) != 'undefined' )
{
var cd = new Date();
if( cd > table.rows[i].timestamp )
{
DeleteRow(table.rows[i].id);
}
else
{
var id = table.rows[i].id;
var timeelemnt = document.getElementById("timeout_"+id);
time = table.rows[i].timestamp - cd;
timeelemnt.innerHTML = Math.ceil( time/1000) +"m";
}
}
}
}
this function is called from timer.
and working fine. but somehow after calling the "DeleteRow(table.rows[i].id);" fucntion, the for loop exists!!. i tried using try catch, but no exception is thrown. any idea.?
Code:
function DeleteRow( rowid )
{
var indx = document.getElementById(rowid).rowIndex;
document.getElementById("Study_List").deleteRow( indx );
document.getElementById("Study_List").deleteRow( indx );
document.getElementById("Study_List").deleteRow( indx );
}
thanks for the reply
-
September 8th, 2008, 12:53 AM
#6
Re: Executing script inside a dynamicaly created table cell
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|