Page 1 of 1

Trigger Javascript from Html Link

Posted: Thu Jun 13, 2013 6:52 pm
by leonardo

Here's what I have currently:
code
var myHtml="&quot
myHtml += "<a href=" +'"'+ linkID + '"' + ">" + "<b>" + "The link test" + "<&#47;b>" + "<&#47;a>"
Tiggzi('panelName')&#46;html(myHtml);/code
On click, instead of navigating to a link, an empty page in this case, I to trigger an event that will call a javascript code.

Thanks for helping.


Trigger Javascript from Html Link

Posted: Thu Jun 13, 2013 7:33 pm
by Maryna Brodina

Hello! Don't use < a tag. Use for example < span tag and style it using CSS.
Code

codevar myHtml="&quot
myHtml += "<span id='someId' class='myLink'>" + "The link test" + "<&#47;span>"
Appery('panelName')&#46;html(myHtml);
$('#someId')&#46;off()&#46;on('click', function() {
&#47;&#47;your code here
});/code

and CSS

code&#46;myLink {
cursor:pointer;
font-weight: bold;
}/code


Trigger Javascript from Html Link

Posted: Thu Jun 13, 2013 8:06 pm
by leonardo

Elegant. Thanks.
Now, after capturing the clicked item in a variable I need to process it with an external JS. How can I call the JS and where in the project should the JS code reside?


Trigger Javascript from Html Link

Posted: Thu Jun 13, 2013 8:33 pm
by Maryna Brodina

Sorry, there was missing information on my reply. I updated it. Please take a look again. You can create JS asset and call any function from that asset (line //your code here)


Trigger Javascript from Html Link

Posted: Thu Jun 13, 2013 9:09 pm
by leonardo

Thanks for the explanation. I actually got that part. So, if I create a JS and call it "processme" under Javascript in my project, how would I accomplish these tasks as shown in that part of the code below?
code
$('#someId')&#46;off()&#46;on('click', function() {
var linkcl=$(this)&#46;text();
1&#46; Pass linkcl to processme
2&#46; Get the returned linkcl after it has been processed
});
/code

  1. Will each JS need to be separate or can I put many JS functions inside the processme JS?

Trigger Javascript from Html Link

Posted: Fri Jun 14, 2013 6:02 am
by Kateryna Grynko

Hi Leonardo,

In processme you can place a number of functions:
codefunction foo( args1, args2 &#47;, &#46;&#46;&#46;&#47;){
&#47;&#47; some code here
}
function bar( args1, args2 &#47;, &#46;&#46;&#46;&#47;){
&#47;&#47; some code here
}/code
And inside of a handler:
code$('#someId')&#46;off()&#46;on('click', function() {
var linkcl=$(this)&#46;text();
var result = foo( linkcl );
&#47;&#47; &#46;&#46;&#46;&#46;&#46;
});/code


Trigger Javascript from Html Link

Posted: Fri Jun 14, 2013 3:58 pm
by leonardo

Thanks so much!