Page 1 of 1

How to call a function from html

Posted: Tue Sep 04, 2018 1:31 pm
by Dirk Geppert
I would like to call a function() from a link. Why doesnt work this with SpideBasic?

Code: Select all


Procedure MyFunc ()
  Debug "You've clicked the link!"
EndProcedure


If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), "")
  
  txt.s = "<h3>Click Test</h3><p>Please click<a href=" + Chr(34) + "#" + Chr(34) + " onclick=" + Chr(34) + "MyFunc();" + Chr(34) + ">here</a>"
  SetGadgetText(0, txt)
EndIf


Re: How to call a function from html

Posted: Tue Sep 04, 2018 1:36 pm
by Dirk Geppert
Got it :D

Code: Select all

Procedure MyFunc ()
  Debug "You've clicked the link!"
EndProcedure


If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), "")
  
  txt.s = "<h3>Click Test</h3><p>Please click<a href=" + Chr(34) + "#" + Chr(34) + " onclick=" + Chr(34) + "window.parent.f_myfunc();" + Chr(34) + ">here</a>"
  SetGadgetText(0, txt)
  
  Debug txt
EndIf


Re: How to call a function from html

Posted: Tue Sep 04, 2018 1:37 pm
by Peter
Hello Dirk,

SpiderBasic converts procedure names into lower case letters and sets a 'f_' - prefix in front of them. For this reason, your call must look like this:

Code: Select all

txt.s = "<h3>Click Test</h3><p>Please click<a href=" + Chr(34) + "#" + Chr(34) + " onclick=" + Chr(34) + "f_myfunc();" + Chr(34) + ">here</a>"
Greetings ... Peter

Re: How to call a function from html

Posted: Thu Sep 06, 2018 11:53 am
by Dirk Geppert
Thx Peter.