PDA

View Full Version : [Solved] Open a Dialog using HREF instead a Button



khrysller
22 Aug 2007, 12:58 PM
Hi...

There is a way to open a dialog using href, something like:


<a href="#" onclick="show-dialog-btn">Open</a>

Instead of using the button:
(example taken from: http://extjs.com/deploy/ext/examples/dialog/hello.html)

<input type="button" id="show-dialog-btn" value="Hello World" />

Thanks.

dantheman
22 Aug 2007, 2:12 PM
You can create a anchor in your HTML, like this:


<a href="javascript:void(0);" id="my-id">Verb</a>


And then attach the listener in your js:


Ext.get('my-id').on('click', function() {
// take action
});


--dan

BernardChhun
22 Aug 2007, 3:34 PM
you may also do something like this:



function displayDialog(animEl){
// a global function
var dialog = new Ext[...];
dialog.show(animEl);
}

// in your html
<a href="javascript:displayDialog(this);">foo</a>

khrysller
23 Aug 2007, 5:49 AM
I tried both ways but didn

dantheman
23 Aug 2007, 6:14 AM
[QUOTE=khrysller;56939]I tried both ways but didn

fay
23 Aug 2007, 6:21 AM
If you are trying this with the extJS \dialog\hello example...

(1) To use dantheman's method:

In HELLO.HTML, change line 25 to:


<a href="javascript:void(0);" id="show-dialog-href">Hello World</a>
In HELLO.JS change line 19 to:


showBtn = Ext.get('show-dialog-href');

(2) To use Bernard's method:

In Hello.HTML change line 25 to:


<a href="javascript:HelloWorld.showDialog();">Hello World</a>

and in HELLO.JS change the call in showDialog to:


dialog.show(); //showBtn.dom);

khrysller
23 Aug 2007, 7:04 AM
Thanks fay, it really help me and make me understand more about ExtJS.

: )