Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button in table is linked wrong 2

Status
Not open for further replies.

Pierro001

Programmer
Feb 8, 2007
6
NL
I have a table with 3 columns en 2 rows. The rows are clickable. Row 1 is hyperlinked to page1.htm en row 2 to page2.htm
So far everthing is working fine.
But now i have placed a button into a cell of the first row wich is hyperlinked to buttonpage.htm

When i click the button it goes to page1.htm instead of buttonpage.htm

I tried to add id's (thanks to monksnake) to the cells and the button to make a if_then_else construction, but nothing works. Who can help me!

This is the code:

<html>
<head>
<script type="text/javascript">

function Goto(Url)
{
document.location.href = Url;
}
</script>


</head>
<body>
<table border="1" width="100%">
<tr id="RowIDid" onclick="Goto('page1.htm');">
<td align="center">1</td>
<td width="384" align="center"><input id="Button_id" type="Button" value="Button" name="B3" onclick="Goto('buttonpage.htm');"></td>
<td width="537" align="center">3</td>
</tr>
<tr id="RowIDid" onclick="Goto('page2.htm');">
<td align="center">4</td>
<td width="384" align="center">5</td>
<td width="537" align="center">6</td>
</tr>
</table>
</body>
</html>
 
The click event is passed back up the object model hierarchy after the element that triggered it has finished with it. So once the button has handled the click it bubbles it's way back up to the row so that the row can handle it's click.
Setting [tt]event.cancelBubble = true;[/tt] should fix your problems.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
It does not go to button_page.htm at all. I goes always to page1.htm no matter if i click the row or the button.
 
After looking DEEEEEEEEP into your code, what dwarfthrower said is correct about the cancelBubble statement, but since you were calling the exact same function it did not get the desired effect.

This is what I came up with (and tested):

Code:
<html>
<head>
<script type="text/javascript">
    
  function Goto(Url, [!]e[/!])
  {
[!]  e.cancelBubble = true;[/!]
  document.location.href = Url;
  }
[!]  
  function GotoRow(Url)
  {
  document.location.href = Url;
  }
[/!]  
  </script>
  
  
</head>
<body>
<table border="1" width="100%">
  <tr id="RowIDid" onclick="[!]GotoRow('page1.htm')[/!];">
  <td align="center">1</td>
  <td width="384" align="center"><input id="Button_id" type="Button" value="Button" name="B3" onclick="[!]
Goto('buttonpage.htm', event)[/!];"></td>
  <td width="537" align="center">3</td>
  </tr>
  <tr id="RowIDid" onclick="Goto('page2.htm');">
  <td align="center">4</td>
  <td width="384" align="center">5</td>
  <td width="537" align="center">6</td>
  </tr>
</table>
</body>
</html>


<.

 
Thank you (dwarfthrower and monksnake) for your help!!!!
 
anytime

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top