use hyperlink to run method

Is it possible to run a method from a hyperlink in a label?

YEP! Starting in Servoy 2.0:

<a href="javascript:formMethod()">Click Here</a>

If you want to pass a parameter to the method:

<a href="javascript:formMethod('1')">Click Here</a>

NOTE: The parameter MUST be enclosed with single quotes!

If you want to call a global method and pass a parameter:

<a href="javascript:globals.method('1')">Click Here</a>

Hope this helps.

Allright! Is this functionality also included in the ‘Help’? That would be nice, too :wink: !

bcusick:
YEP! Starting in Servoy 2.0:

<a href="javascript:formMethod()">Click Here</a>

Hmmm.. I do see the HTML correct in the label, but the method just doesn’t run… this is what I do:

<a href="javascript:SearchA()">A</a>

Any idea what’s missing here?

Looks like you are creating a search by letters. I do the same, here is the code that works for me

var method = yourmethod
var letter = new Array('a', 'b', ...)

// I use this in a loop over my letter array
// this portion just takes care of creating the link!
html += '<td align="center"><a href="javascript:'
html += method + '(\''
html += letter[i]
html += '\')">'
html += letter[i]
html += '</a></td>'

Hope it helps.

patrick:
Looks like you are creating a search by letters.

That’s right! I try to use a label with HTML code to activate the search method. The result appears in a tableview and not in HTML though… Thing is that the method just not activates from clicking on the hyperlink in the label…

Wouldn’t it be easier if you construct your search as

<a href="javascript:Search('A')">A</a>

and in that method Search you do a

var letter = arguments[0] // delivers A in the example above

That way you only need 1 search method and not one for every letter.

Your problem might be that the method SearchA is not in the same form as the html? Then it should be forms.your_table_view.searchA().

freecolours:
Allright! Is this functionality also included in the ‘Help’? That would be nice, too :wink: !

Karl,

This functionality is included in the online Servoy Help
Navigator as well as in the printed Servoy Developer Edition Volume 1:
User’s Guide under the Fields section.

In the Servoy Help Navigator:

  • Choose Help>Help (F1).
    -Click once to select the Index tab.
    -Enter “method” in the search criteria box.
    -Double click on the sub-index entry “Calling a method from a field”.

This will open the Fields section.

-Choose Tools>Find.
-Enter “calling a method” in the “Find What” box.
-Press the “Find Next” button to go directly to the information and
example on “Calling a method directly from a field”.

In the printed Servoy Developer Edition Volume 1: User’s Guide:

See the Chapter 7 Forms; Section 7.9 Form elements;
Subsection 7.9.3.2 Calling a method directly from a field; page 203.


Marc Norman
Servoy

freecolours:
Allright! Is this functionality also included in the ‘Help’? That would be nice, too :wink: !

If you would have actually read the help you would also know that you have to put the html in a global field instead of on a label.

jaleman:
If you would have actually read the help you would also know that you have to put the html in a global field instead of on a label.

That’s what I wanted to hear! Hyperlinks don’t work in labels, but in globals! (HTML works fine in labels, though…)
I wonder if the help really does say that you can’t use hyperlinks in labels… But thanks anyway, Jan!

freecolours:
I wonder if the help really does say that you can’t use hyperlinks in labels… But thanks anyway, Jan!

How about reading the help? Using hyperlinks is discussed in the fields chapter and not in the labels chapter, I wonder if that is coincidence.