PDA

View Full Version : how can i call a java script function in XTemplate



arunkumargm1987
18 Jun 2010, 3:00 AM
I have a XTemplate defined as given below



var htmlsuggestions='</br><tpl for=".">'
'<tpl if="suggestion != &quot;&quot;">'
'<div class="search-suggection">'
'<a href="#" onClick="clickFunction()"><h3>Did you mean:{suggestion}</h3></a>'
'<hr>'
'</div>'
'</tpl>'
'</tpl>';
And the javascript function as defined below.


function clickFunction()
{
//code here
}
When i click on the link.

I see a error in firebug

"clickFunction() is undefined"

Please help.

arunkumargm1987
18 Jun 2010, 3:27 AM
Please Help.

Condor
18 Jun 2010, 3:30 AM
This only works if clickFunction is a global function.

window.clickFunction = function(){
// code here
}

Animal
18 Jun 2010, 4:25 AM
You'd be far better off implementing a single click handler on the outermost Element of your Component and using



delegate: 'div.search-suggection'

Animal
18 Jun 2010, 4:26 AM
Or, if it's a DataView, check DataView's events.