---
title: "Three ways to use button with event"
author: "bluestorm"
date: "2009-10-08T23:27:54Z"
tags: []
slug: "three-ways-to-use-button-with-event"
draft: false
lastmod: "2009-10-08T23:32:30Z"
id: 483199
url: "https://bluestorm.iteye.com/blog/483199"
---

There are three ways to use button with event. Following are three samples.

 

```
/**
 * The first way to use button with event: default event is "onclick".
 * 
 *
*/

<script type="text/javascript">

	Ext.onReady(function(){

		new Ext.Button([
			renderTo: Ext.getBody(),
			text: "Confirm",
			handler: function(){
				alert("Welcome to ExtJS world!");
			}
		
		]);
	});

</script>
```

 

 

```
/**
 * The second way to use button with event.
*/

<script type="text/javascript">

	Ext.onReady(function(){

		new Ext.Button([
			renderTo: Ext.getBody(),
			text: "Confirm",
			listeners: {
				"click": function(){
					alert("Welcome to ExtJS world!");
				}

			}
		
		]);
	});

</script>
```

 

 

```
/**
 * The third way to use button with event.
*/

<script type="text/javascript">

	Ext.onReady(function(){

		var _button = new Ext.Button([
			renderTo: Ext.getBody(),
			text: "Confirm"		
		]);

		_button.on("click", function(){
				         alert("Welcome to ExtJS world!");
			              });
	});

</script>
```