Getting Controls in JavaScript

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

How do I get the control that generated an event in Javascript?

I can do something like:

var checkBox = document.getElementById('DataGrid1__ctl2_Choice');

But that doesn't tell me what object generated the call.

Thanks,

Tom
 
normally you pass it.


<input id="chk1" name="chk1" type="checkbox" onclick="doClick(this);" />
<script>doClick(e){alert(e.id);}</script>

-- bruce (sqlwork.com)
 
I know that is a way.

But I am using an AJAX component (Anthem) that does a PreCallBack function
where it allows preprocessing but doesn't seem to have a way to find out
what object caused the event.

***********************************
<script language="javascript">
function Anthem_PreCallBack()
{
if (!confirm("Are you sure you want to upload this job? \n\nThis will
cause your credit card to be charged"))
{
var checkBox = document.getElementById('DataGrid1__ctl2_Choice');
alert("checkBox checked = " + checkBox.checked);
checkBox.checked = false;
return false;
}
}
</script>
**********************************

The above script won't work as it assumes you know the ID - which of course
you don't if part of a DataGrid.

There may not be a way to do this, as this is a call that Anthem does
internally, but I was just curious if there was another way to do this.

Thanks,

Tom
 
Back
Top