How to call a function from html

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

How to call a function from html

Post 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

Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: How to call a function from html

Post 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

User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: How to call a function from html

Post 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
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: How to call a function from html

Post by Dirk Geppert »

Thx Peter.
Post Reply