Atozed Forums
Callback questions - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Callback questions (/thread-1578.html)



Callback questions - davidmcevoy@outlook.com - 03-09-2020

Hello, I was just wondering if it is possible to create a callback function that take an ID value as an input and outputs text back to the browser that can be used to fill a DIV with.

What I have is a table that has a hidden DIV underneath each row.  on clicking the header the div expands and becomes visible, and I am hoping to dynamically fill the DIV with content at this point only to reduce data traffic.

Is this possible, and if so, does anyone have any code snippets they would care to share?

I am new to the use of Ajax/Callback functions and I have tried playing around but not getting very far so far.

David.


RE: Callback questions - Alexandre Machado - 03-11-2020

Hi,

this code exemplifies it:

Code:
procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
var
  jsCode: string;
begin
  jsCode := 'IW.$("mydiv").innerHTML = "my new text";';
  WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(jsCode);
end;

In that case I have a div which id is "mydiv" (remember that JavaScript is case sensitive). When clicking a button on my form I want to set its text to "my new text".

WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA()

is just a long line to instruct IW JavaScript libraries to run that line of code, referenced by js local variable.

Please let me know if that helps.


RE: Callback questions - davidmcevoy@outlook.com - 03-11-2020

(03-11-2020, 11:15 AM)Hi Alexandre.Thanks for this, it is more or less what I have but I have created a callback function as my code is getting called directly from the HTML onClick event rather than an IW control.  Your JS looks a lot neater than mine though :-)Alexandre Machado Wrote: Hi,

this code exemplifies it:

Code:
procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
var
  jsCode: string;
begin
  jsCode := 'IW.$("mydiv").innerHTML = "my new text";';
  WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA(jsCode);
end;

In that case I have a div which id is "mydiv" (remember that JavaScript is case sensitive). When clicking a button on my form I want to set its text to "my new text".

WebApplication.CallBackResponse.AddJavaScriptToExecuteAsCDATA()

is just a long line to instruct IW JavaScript libraries to run that line of code, referenced by js local variable.

Please let me know if that helps.