<tr> and onclick and a checkbox...

S

Sonnich Jensen

Hi all!

I have a table, with some items and a checkbox in the last column, for
seleting.
I have an onclick event for the row on the <tr tag, so the entire row
is clickable, that is easier when going throug a list.
The problem I have is that the checkbox, when being clicked will
toggle and then again on the rows event.
It will be toggled twice causing it not to work... well both works...

I have tried to stop the rows event by an onclick on the checkbox, but
that did not work well...

Can anyone help me on this?`

BR
Sonnich

--- table row with event
<tr id='div_$i' onMouseUp=\"check_item('sel_$i');\" >
---- coloumn with checkbox
<td align=\"center\"><input name=\"sel_$i\" type=\"checkbox\" value=
\"$part1[$i]\"

and some JS to handle the row...

function check_item(sel_item)
{
var i;
v = document.forms["myform"];
i=0;
while( (i < v.elements.length) && (v.elements.name !=
sel_item) )
i++;
if(i < v.elements.length)
v.elements.checked= !v.elements.checked;
}
 
B

Bart Van der Donck

Sonnich said:
I have a table, with some items and a checkbox in the last column, for
seleting.
I have an onclick event for the row on the <tr tag, so the entire row
is clickable, that is easier when going throug a list.
The problem I have is that the checkbox, when being clicked will
toggle and then again on the rows event.
It will be toggled twice causing it not to work... well both works...

I have tried to stop the rows event by an onclick on the checkbox, but
that did not work well...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>My cool web page</title>
<script type="text/javascript">
function alter()
{
if (document.forms[0].box.checked) {
document.forms[0].box.checked = false
}
else {
document.forms[0].box.checked = true
}
}
</script>
</head>
<body>
<form action="script.php">
<table border="1">
<tr onClick="alter()"
onMouseOver="this.style.backgroundColor='yellow'"
onMouseOut="this.style.backgroundColor='white'"
style="background-color:white"<td>xx</td>
<td><input type="checkbox" name="box" onClick="alter()"></td>
</tr>
<tr>
<td>xx</td>
<td>xx</td>
</tr>
</table>
</form>
</body>
</html>

Hope this helps,
 
B

Bart Van der Donck

Sonnich said:
I have a table, with some items and a checkbox in the last column, for
seleting.
I have an onclick event for the row on the <tr tag, so the entire row
is clickable, that is easier when going throug a list.
The problem I have is that the checkbox, when being clicked will
toggle and then again on the rows event.
It will be toggled twice causing it not to work... well both works...

I have tried to stop the rows event by an onclick on the checkbox, but
that did not work well...

Here is another way:

<table border="1">
<tr>
<td><label for="box1">xx</label></td>
<td><input type="checkbox" name="box1" id="box1"></td>
</tr>
<tr>
<td><label for="box2">xx</label></td>
<td><input type="checkbox" name="box2" id="box2"></td>
</tr>
</table>
 
E

Evertjan.

Bart Van der Donck wrote on 23 aug 2007 in comp.lang.javascript:
function alter()
{
if (document.forms[0].box.checked) {
document.forms[0].box.checked = false
}
else {
document.forms[0].box.checked = true
}
}

Dag Bart,

function alter(){
document.forms[0].box.checked = !document.forms[0].box.checked;
};
 
B

Bart Van der Donck

Evertjan. said:
Bart Van der Donck wrote on 23 aug 2007 in comp.lang.javascript:
function alter()
{
if (document.forms[0].box.checked) {
document.forms[0].box.checked = false
}
else {
document.forms[0].box.checked = true
}
}

Dag Bart,

function alter(){
document.forms[0].box.checked = !document.forms[0].box.checked;

Daar moet ge een Hollander voor zijn om zoiets te kunnen bedenken :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top