Forum Moderators: open

Message Too Old, No Replies

radio to change onclick behaviour

open or check the checkbox

         

mcibor

11:06 am on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a table with links to data. I can either open the data (normal <a href) or check the checkbox

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

RonPK

1:50 pm on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe this helps:

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.

mcibor

10:30 am on Nov 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I didn't manage finally to achieve the desired effect - IE couldn't open neither window.location.href nor window.open when it was in outer file in function. However I went around the problem and made one row clickable, and the other checkable.

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)...