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=""
myHtml += "<a href=" +'"'+ linkID + '"' + ">" + "<b>" + "The link test" + "</b>" + "</a>"
Tiggzi('panelName').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=""
myHtml += "<span id='someId' class='myLink'>" + "The link test" + "</span>"
Appery('panelName').html(myHtml);
$('#someId').off().on('click', function() {
//your code here
});/code
and CSS
code.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').off().on('click', function() {
var linkcl=$(this).text();
1. Pass linkcl to processme
2. Get the returned linkcl after it has been processed
});
/code
- 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 /, .../){
// some code here
}
function bar( args1, args2 /, .../){
// some code here
}/code
And inside of a handler:
code$('#someId').off().on('click', function() {
var linkcl=$(this).text();
var result = foo( linkcl );
// .....
});/code
Trigger Javascript from Html Link
Posted: Fri Jun 14, 2013 3:58 pm
by leonardo