Dotnetinfo’s Weblog

Just another WordPress.com weblog

Archive for the ‘Javascript’ Category

Dynamically adding events in Javascript

Posted by dotnetinfo on March 12, 2009

I was working on a small project to create some buttons dynmicaly using javascript .

 var oCel2 = newRow.insertCell(4);
var button = document.createElement(‘input’);
button.setAttribute(‘type’,'button’);
button.setAttribute(‘name’,'button1′)
button.setAttribute(‘id’,'button1′)    
button.setAttribute(‘value’,'Delete’);     
// button.onclick= ‘removeRow(this)’; // wrong way – adding  text not a function

button.onclick= new Function(‘removeRow(this)’); // correct way – adding a function
oCel2.appendChild(button);

Hope it helps someone. Thanks

Posted in Javascript | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.