Page 1 of 1

How to use the callback function with drop down option

Posted: Fri Aug 29, 2014 11:39 pm
by viiartz

Code: Select all

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Web_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 450, 200, 400, 400, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    WebGadget(#Web_0, 15, 30, 360, 200, "")
	EndIf
EndProcedure

Procedure NavigationCallback(Gadget,URL$)
  CallDebugger
  If FindString(URL$,":",1)>0
		MessageRequester("",URL$)
	EndIf	
  ;ProcedureReturn #True
EndProcedure

OpenWindow_Window_0()
lookup$=""
lookup$+"<select name="+Chr(34)+"Base Currency"+Chr(34)+">"
lookup$+"  <option selected value="+Chr(34)+"AUD"+Chr(34)+">Australia Dollar AUD</option>"
lookup$+"  <option value="+Chr(34)+"USD"+Chr(34)+" onClick='window.location=" + #DQUOTE$ +":USD" + #DQUOTE$ + "'>USA Dollar USD</option>"
lookup$+"  <option value="+Chr(34)+"GBP"+Chr(34)+">British Pound GBP</option>"
lookup$+"  <option value="+Chr(34)+"EUR"+Chr(34)+">Euro EUR</option>"
lookup$+"  <option value="+Chr(34)+"NGN"+Chr(34)+">Nigeria Naira NGN</option>"
lookup$+"  <option value="+Chr(34)+"GHC"+Chr(34)+">Ghanaian Cedi GHC</option>"
lookup$+"  <option value="+Chr(34)+"TZS"+Chr(34)+">Tanzanian Shilling TZS</option>"
lookup$+"  <option value="+Chr(34)+"XOF"+Chr(34)+">CFA Franc XOF</option>"  
lookup$+"</select>"

txt.S=GetGadgetItemText(#Web_0,#PB_Web_HtmlCode)

SetGadgetItemText(#Web_0,#PB_Web_HtmlCode,lookup$)


;{- Event loop
Repeat
	SetGadgetAttribute(#Web_0, #PB_Web_NavigationCallback, @NavigationCallback())
  Event = WaitWindowEvent()
  Select Event
			; ///////////////////
		Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Web_0
			EndIf
			; ////////////////////////
		Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
			EndIf
	EndSelect
ForEver
;
;}
Hi all,

Please I need help. What is the "onClick" function that I need to use to trigger the NavigationCallback function on my test code, when I click on the Drop-Down-List option "USA Dollar USD" on the WebGadget.

What I'm expecting to happen is that when I choose/click on the option "USA Dollar USD" I will get a message requester showing me the URL$ string that is passed to the Callback function, but I'm not getting anything!

Any help or advice would be greatly appreciated!

Re: How to use the callback function with drop down option

Posted: Sat Aug 30, 2014 12:06 am
by IdeasVacuum
Neither PB or Windows OS will detect that selection on your mini web page natively. There might be a clever way to do it, you basically just want to know if the gadget was clicked and if so, what item is active.

What you have there is obviously only a snippet describing the one issue. If you need other interaction with a web page, you may need to look at Javascript/HTML5 for the solutions.

Re: How to use the callback function with drop down option

Posted: Sat Aug 30, 2014 12:00 pm
by Shardik
viiartz wrote:What is the "onClick" function that I need to use to trigger the NavigationCallback function on my test code, when I click on the Drop-Down-List option "USA Dollar USD" on the WebGadget.
In your code example you tried to implement the onClick event in your option definition for USD. Unfortunately that doesn't work. You have to put the onClick event or even better the onChange event into the select statement. To obtain the chosen option in the NavigationCallback() you have to change the select statement to the following:

Code: Select all

lookup$+"<select name='Base Currency' onChange='window.location=this.value'>"
By using 'window.location=this.value' the NavigationCallback() will receive "about:EUR" in URL$ when selecting "Euro EUR".

This is your modified working example:

Code: Select all

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Web_0
EndEnumeration
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure OpenWindow_Window_0()
  If OpenWindow(#Window_0, 450, 200, 400, 400, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
    WebGadget(#Web_0, 15, 30, 360, 200, "")
  EndIf
EndProcedure

Procedure NavigationCallback(Gadget,URL$)
  MessageRequester("Info", "Selected currency: " + StringField(URL$, 2, ":"))
EndProcedure

OpenWindow_Window_0()
lookup$+"<select name='Base Currency' onChange='window.location=this.value'>"
lookup$+"  <option selected value='AUD'>Australia Dollar AUD</option>"
lookup$+"  <option value='USD'>USA Dollar USD</option>"
lookup$+"  <option value='GBP'>British Pound GBP</option>"
lookup$+"  <option value='EUR'>Euro EUR</option>"
lookup$+"  <option value='NGN'>Nigeria Naira NGN</option>"
lookup$+"  <option value='GHC'>Ghanaian Cedi GHC</option>"
lookup$+"  <option value='TZS'>Tanzanian Shilling TZS</option>"
lookup$+"  <option value='XOF'>CFA Franc XOF</option>" 
lookup$+"</select>"

SetGadgetItemText(#Web_0,#PB_Web_HtmlCode,lookup$)


;{- Event loop
Repeat
  SetGadgetAttribute(#Web_0, #PB_Web_NavigationCallback, @NavigationCallback())
  Event = WaitWindowEvent()
  Select Event
      ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = #Web_0
      EndIf
      ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver
;
;}

Re: How to use the callback function with drop down option

Posted: Sat Aug 30, 2014 6:38 pm
by viiartz
Thank you so much Shardik, you're a legend. :D

I've been trawling the net trying to figure it out. I knew that there must be a way to achieve what I wanted!
Thanks for taking the time to modify the code to show me the example!

Is there any detailed help or tutorial on using the callback function with the webGadget? What I have found on this board is very limited!

Again thank you!

Re: How to use the callback function with drop down option

Posted: Sat Aug 30, 2014 8:54 pm
by IdeasVacuum
That is a clever way to do it Shardik! 8)