[Pas2js] Call a function from html
Michael Van Canneyt
michael at freepascal.org
Wed Sep 4 08:24:01 CEST 2019
On Tue, 3 Sep 2019, Gabriele Cappelletto via Pas2js wrote:
> Hello
> I would like to find a way to call a function written with pas2js from
> html code (do not define onclick from pas2js, but call from html)
>
> example
> html
> ?<input type="button" class="form-control" id="btn3" value="direct mode"
> onclick="Btn1Click();"/>
All functions live under the top-level "pas" object, per unit.
So
onclick=pas.YourUnit.Yourfunction()
should do it.
Here YourUnit and YourFunction are of course case sensitive.
If the function is in the main program, then you must write
onclick=pas.program.Yourfunction()
with the identifier "program" in lowercase letters.
You must make sure that rtl.run() has been called when the page loads.
>
> and the Btn1Click function write it with pas2js.
> example
> function Btn1Click(aEvent: TJSMouseEvent): boolean;
> begin
> ? //?
> end;
>
> How can I do?
Just write your function, and refer to it in the above manner.
Michael.
More information about the Pas2js
mailing list