Click to See Complete Forum and Search --> : Force event on another object


kopite
04-24-2003, 09:35 AM
Hi,

I have a row onclick event - I want that event to go and fire off an event defined on a checkbox of the same row.

How do I do that?

That is, I want to force the checkBox7 event, so that setValues("1", "1020", 7) will run when ive clicked the row in which it resides.

<input type="checkbox" name="checkBox7" onClick='setValues("1", "1020", 7)'>

Cheers!

Jona
04-24-2003, 09:38 AM
:confused: Is this a table row (<tr>)? onClick="do_some_function();"

function do_some_function(){
setValues("1","1020",7);
}

kopite
04-24-2003, 09:50 AM
It is a table row... but do_some_function() will not know the values to pass to the setValues function.

The only element that will know it is the checkbox on the same row.

Jona
04-24-2003, 09:52 AM
The checkbox value should be value="1,1020,7" and then use split() and join() to get out the three seperate values.

Charles
04-24-2003, 10:04 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="" name="king">
<div>
<input type="checkbox" name="tut" onclick="alert('Amonhotep IV')">
<input type="button" onclick="king.tut.onclick()">
<div>
</form>

Jona
04-24-2003, 10:08 AM
Charles, I thought valid HTML meant that you had to close your tags--<div>'s included...

Charles
04-24-2003, 10:15 AM
That was a typographical error. However, in HTML you do not have to "close your tags" for all elements. It's a terribly messy situation which is why we now have XHTML. (In the case of the DIV element, both tags are required.)

kopite
04-24-2003, 10:40 AM
why do i need the div tags, will not this work:

<form action="" name="king">
<input type="checkbox" name="tut" onclick="alert('Amonhotep IV')">
<input type="button" onclick="king.tut.onclick()">
</form>

Charles
04-24-2003, 11:36 AM
My example was in HTML 4.01 Strict and in 4.01 Strict the FORM element can only immediately contain block level elements and the form controls are inline level elements. This restriction does not apply to HTML 3.2 or to HTML 4.01 Transtional. This restriction was added, no doubt, for some good reasons but I don't know what they are. (I have my guesses, but I don't know.)

kopite
04-24-2003, 12:23 PM
thanks:)

kopite
04-27-2003, 12:55 PM
Hmmmm, did does not work for all usage, and this is all within the same IE document:

It is okay when I do this which is fired when I click a row:

function setCheckBox(index)
{
var chkbox = "checkBox" + index;

if ( document.getElementById(chkbox).checked == true )
document.getElementById(chkbox).checked = false;
else
document.getElementById(chkbox).checked = true;

document.getElementById(chkbox).onclick();
}

but when I try and call setCheckBox from another function, the onclick event does not proceed, no errors, does nothing, comes to a halt at the forcing of the event, this is also the case when I put the code directly in myOtherFunc (i.e. : document.getElementById(chkbox).onclick(); )

function myOtherFunc(index)
{
setCheckBox(index)
}

Do not know why - any ideas?

thanks