You are here: Re: Table Row Background onClick? « HTML « IT news, forums, messages
Re: Table Row Background onClick?

Posted by afrinspray on 09/01/06 22:15

Wow thanks so much! I can't believe you put so much time into helping
me. GregAgee@gmail.com, you are a godsend.

Bless your heart,
Afrinspray


GregAgee@gmail.com wrote:
> Hey there Afrinspray,
>
> To make sure I understand your question, you only want to perform some
> action when a row is clicked, but not specific elements in that row?
>
> One way to solve this problem is, first, to figure out what element the
> user clicked (i.e. a selection list, or a checkbox, etc). Then create
> an array of those elements' ids to check against. With this array you
> can traverse though it and check to see if the element that was clicked
> is in the 'noAction' array, otherwise, perform the desired action.
> Here is some example code that you can check out (works on firefox and
> IE 6):
>
> <html>
> <head>
> <title>MouseClick Test</title>
> </head>
>
> <body>
>
> <script language="javascript" type="text/javascript">
>
> /* do something unless certain elements were clicked... */
> function doSomething(mouseEvent) {
> var elementID;
> //if event doesn't exist,
> //use window.event
> if(!mouseEvent)
> mouseEvent = window.event;
>
> // get the id of the element that was clicked (firefox)
> if(mouseEvent.target)
> elementID = mouseEvent.target.id;
> // get the id of the element that was clicked (IE)
> else if(mouseEvent.srcElement)
> elementID = mouseEvent.srcElement.id;
>
> // perform the desired action UNLESS these
> // elements are clicked
> var noActionIDs = new Array();
> noActionIDs[0] = "checkboxID";
> noActionIDs[1] = "selectID";
>
> for(var i = 0; i < noActionIDs.length; i++) {
> if(elementID == noActionIDs[i])
> return;
> }
>
> performAction();
> }
>
> /* alert when the row was clicked, but not the
> * specified elements
> */
> function performAction() {
> alert("The row was clicked!");
> }
>
> </script>
>
> <table border="1">
> <tr onclick="doSomething(event)">
> <td>
> <input type="checkbox" id="checkboxID" />
> </td>
> <td>
> <select id="selectID">
> <option>Some Option</option>
> </select>
> </td>
> <td>
> <span>blah blah blah blah</span>
> </td>
> <td>
> <span>bloo bloo bloo bloo</span>
> </td>
> </tr>
> </table>
>
> </body>
> </html>
>
>
> (hope this helps)
>
>
> afrinspray@gmail.com wrote:
> > I have a table row with a dropdown and a checkbox, but I want the table
> > rows onClick event to fire only when the user clicks the background of
> > the row and not the dropdown or checkbox. How can I do this?
> >
> > Thanks,
> > Mike

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация