...

View Full Version : javascript function on table row but not on image inside table row



jpavlik
09-01-2010, 03:23 PM
My issue is that I have a javascript function applied on page load via an addLoadEvent function call in the head to every row (dynamic number of records retrieved) on a table. On every row of the table I also have an element (image or button) that performs a different function that is assigned on the element itself. Unfortunately, when I click the element it also performs the function that was applied to the row in the page load. Is there any way to not call this function on element click? I know usually you include code, but due to the nature of the work I am limited in that respect. Basically its:



<script type="text/javascript">
addLoadEvent(function() { function1(1); })
//function1 makes the table rows do something appearance wise.
</script>

<tr>
<td></td>
<td></td>
<td>
<img src="pics/delete.png" alt="Delete" onclick="function2();">
</td>
</tr>


I apologize if my post doesn't conform to the general guidelines of proper posting on this board. I'm new on this site.

DaveyErwin
09-01-2010, 03:30 PM
My issue is that I have a javascript function applied on page load via an addLoadEvent function call in the head to every row (dynamic number of records retrieved) on a table. On every row of the table I also have an element (image or button) that performs a different function that is assigned on the element itself. Unfortunately, when I click the element it also performs the function that was applied to the row in the page load. Is there any way to not call this function on element click? I know usually you include code, but due to the nature of the work I am limited in that respect. Basically its:



<script type="text/javascript">
addLoadEvent(function() { function1(1); })
//function1 makes the table rows do something appearance wise.
</script>

<tr>
<td></td>
<td></td>
<td>
<img src="pics/delete.png" alt="Delete" onclick="function2();">
</td>
</tr>


I apologize if my post doesn't conform to the general guidelines of proper posting on this board. I'm new on this site.

Yes, I have a very simple and easy to apply solution,
but due to the proprietary nature of the work I cannot
post it here.

codebyter
09-01-2010, 03:33 PM
I'm assuming you are using event listeners for attaching the events? It sounds to me that your events are bubbling down because it seems like a problem with event delegation

jpavlik
09-01-2010, 03:49 PM
the function1(1) is:



function function1(numtables){
for (var tablecount=1; tablecount<=numtables;tablecount++)
{
var table = document.getElementById('rsTableBody' + tablecount);
for (var i=0;i<table.rows.length;i++) {
if (table.rows[i].className == 'nofunction') { /* Do nothing */ }
else {
table.rows[i].onclick= function () {
//do stuff
}

jpavlik
09-09-2010, 05:59 PM
Any ideas on this?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum