Dotnetinfo’s Weblog

Just another WordPress.com weblog

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

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.