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

How to call a function from html

by Dirk Geppert Tue Sep 04, 2018 1:31 pm

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: 73
Joined: Fri Sep 22, 2017 7:02 am

Re: How to call a function from html

by Dirk Geppert Tue Sep 04, 2018 1:36 pm

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: 525
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: How to call a function from html

by Peter Tue Sep 04, 2018 1:37 pm

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: 73
Joined: Fri Sep 22, 2017 7:02 am

Re: How to call a function from html

by Dirk Geppert Thu Sep 06, 2018 11:53 am

Thx Peter.
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 1 guest