Wiring up javascript events and passing parameters
<p><strong>A bit background:</strong>
I've got a page with a table and a number of checkboxes.  The page is generated in asp.net.
Each row has a checkbox, there's a checkbox in the header, and in certain cells there will be groups of check boxes (you get the picure lots of checkboxes).</p>

<p>Each of these check boxes currently works fine with a little bit of javascript magic in their onclick events.</p>

<p>so you have something like:</p>

<pre><code>&lt;td&gt;&lt;input type="checkbox" id="sellRow1" onclick="javascript:highlightRow(this, 'AlternateRowStyle1');"/&gt;&lt;/td&gt;
</code></pre>

<p>Not much of a surprise there then.</p>

<p><strong>Ok so the here's the problem:</strong>
So this works fine however I need each of the check boxes to reflect the states of other checkboxes. So for example: the checkbox in the header changes the values of the row checkboxes, changes to the row checkboxes can change the header check box etc.</p>

<p>I know what you're thinking: easy just call that Javascript function <code>highlightRow</code>. 
But if I did how would I get the parameters (ok the <code>this</code> is easy but where on earth could I get that <code>'AlternateRowStyle1'</code>?)</p>

<p><strong>So I guess the question is:</strong> Where do I put those parameters so I can get at them with JS in a nice cross browser way. (<code>&lt;PossibleRedHerring&gt;</code>tried putting custom attributes on each checkbox but wasn't sure that was the correct way to go<code>&lt;/PossibleRedHerring&gt;</code>), also I'd prefer not having to keep calling back to the server if that's at all avoidable. </p>

<p><hr /></p>

<p>(btw sorry if this is a bit badly formatted / written, I'm extraordinarily tired!)</p>

<p><hr /></p>

<p><strong>Update:</strong>
Ok so in the end I managed to dodge the custom attributes as noticed that there was a hierarchy to the check boxes.  This meant I was able to trigger the click event of the child checkboxes (which inturn would call it's childrens' click event etc) luckily in this case the flow will never go in the opposite direction causing an infinite loop (there are a lot of comments / documentation to point this out!)</p>

<p>The only interesting thing with this is the difference between click events in IE and in firefox, chrome and safari.  IE allows anything to have a click where as the others limit click to INPUT elements of type button, checkbox, radio, reset or submit. I kind of wanted to use event bubbling to attach the click events to an element that contained a group of checkboxes. </p>

<p>In the end went with a bit of a hack:</p>

<pre><code>// In IE every element supports Click wilst Firefox (also chrome and safari) only supports INPUT elements of type button, checkbox, radio, reset or submit
// https://developer.mozilla.org/en/DOM/element.click
// this function allows both browers to support click on all elements
function FireClickEvent(element)
{
    if (element.click)
    {
        element.click();
    }
    else
    {
        // We don't have a click on this element, so add our own.
        var evt = document.createEvent("MouseEvents");
        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        element.dispatchEvent(evt);
    }
}
</code></pre>

<p>Think that could be somewhat improved but it does the business for now.</p>

<p>Should also admit this was my first shot at proper javascript. It's a bit of a scary language (esp when hitting the dom!) interesting though, am looking forward to spending a bit of time delving in further.</p>
