J
jiayanxiang
Hi:
I used the following code to dynamically add a control and I tried to
use attachevent to add a onClick event to the control. It doesn't seem
to do anything. Any idea what might be wrong?
Thanks.
<HTML>
<HEAD>
<script language="javascript">
function AddOneCtl() {
var ni = document.getElementById('myDiv');
var newctl2 = document.createElement('button');
newctl2.setAttribute('id','Test1');
newctl2.setAttribute('value','Click Me');
ni.appendChild(newctl2)
document.getElementById('Test1').attachEvent('onClick',clickevt1);
}
function clickevt1() {
alert("Clicked");
}
</script>
</HEAD>
<BODY>
<FORM name="AddControl">
<INPUT TYPE="button" VALUE="Click here to add a control"
onClick="AddOneCtl()">
</FORM>
<div id="myDiv"> </div>
</BODY>
</HTML>
I used the following code to dynamically add a control and I tried to
use attachevent to add a onClick event to the control. It doesn't seem
to do anything. Any idea what might be wrong?
Thanks.
<HTML>
<HEAD>
<script language="javascript">
function AddOneCtl() {
var ni = document.getElementById('myDiv');
var newctl2 = document.createElement('button');
newctl2.setAttribute('id','Test1');
newctl2.setAttribute('value','Click Me');
ni.appendChild(newctl2)
document.getElementById('Test1').attachEvent('onClick',clickevt1);
}
function clickevt1() {
alert("Clicked");
}
</script>
</HEAD>
<BODY>
<FORM name="AddControl">
<INPUT TYPE="button" VALUE="Click here to add a control"
onClick="AddOneCtl()">
</FORM>
<div id="myDiv"> </div>
</BODY>
</HTML>