I'm trying to get JavaScript to execute correctly when either clicking a checkbox, or clicking a <tr>. However it seems to be executing the code twice; once for the checkbox and once for the <tr>.
Now you may say "Why not just put it on the checkbox and be done with it?" If it was that simple, I would have done that. But it was requested to have it trigger when they click the <tr> or on the checkbox.
Now to add some more complexity, when the onClick fires, it sends the data back to the parent, in an array, for processing until it is time for the update.
Child Window (Problem area)
function FnSearch(urembroid, embroideryID){
if (document.getElementById("embroid"+embroideryID).checked == false){
try {
parent.window.EmbroideryDataReturned("add", embroideryID);
} catch(e) {
window.opener.parent.EmbroideryDataReturned("add", embroideryID);
}
document.getElementById("embroid"+embroideryID).checked = true;
} else {
try {
parent.window.EmbroideryDataReturned("remove", embroideryID);
} catch(e) {
window.opener.parent.EmbroideryDataReturned("remove", embroideryID);
}
document.getElementById("embroid"+embroideryID).checked = false;
}
Child window HTML -- Please note PHP is making the and fields.
echo "<tr id='embroideryData' onclick=\"javascript:FnSearch('" . $data['urembroidid'] . "', '".$data['EmbroideryID']."')\">"; // On a <tr> execute the update
if (OrderKeyExists($data['EmbroideryID'])) {
echo "<td id='checkbox'><input type='checkbox' id='embroid".$data['EmbroideryID']."' checked='checked'/></td>";
} else {
echo "<td id='checkbox'><input type='checkbox' id='embroid".$data['EmbroideryID']."'/></td>";
}
echo "</tr>\n";
I only need this code to execute once. The code works correctly when clicking on the <tr> but executes twice when the checkbox is clicked on. However it also messes up the array inside the parent window to where it could have false data when clicking on the checkbox. When debugging, it sends a onClick to FnSearch as if the checkbox was originally "checked" when it was not. So it sends a "remove" to the parent, but the second time it does the complete opposite. This is causing the data integrity.
So the main question is: How do you get the checkbox to only execute FnSearch once?
If anyone has any input, that would be greatly appreciated!
<tr>, correct?