Forum Moderators: open
I want to add an onclick statement in <tr that will either open the data
<tr onClick="window.location.href='data.html'">
or check the checkbox
<tr onMouseDown="document.getElementById('c1').checked = (document.getElementById('c1').checked? false : true)"><td><input type="checkbox" id="c1" name="check[]">
How can I change the action depending on the radio?
<input type="radio" name="tr" id="tr" value="check">... value="link">
Best regards
Michal Cibor
function toggleTrEvent(radioEl) {
var trEl = [get a pointer to the tr];
if (radioEl.checked) {
trEl.onclick = function () {
// js-statements here
};
} else {
trEl.onclick = function () {
// the other js-statements here
};
}
}
..
<input type="checkbox" onclick="toggleTrEvent(this)">
Untested.
Otherwise you may need to look into attachEvent / removeEvent and their counterparts for other browsers.
Thanks by the way!
Michal Cibor
PS. To check if the radio was checked was harsh. I found this code somewhere:
<input type="radio" id="cc">....
if(document.getElementById('cc').checked)...