Atozed Forums

Full Version: Get value from Javascript to Label
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In javascript I have a function that returns ID. 
I want to read this value from HTML javascript and display it on the Label.

procedure TMainForm.IWAppFormCreate(Sender: TObject);
begin

AddToInitProc('function GetId() { return 5; }');

end;


procedure TMainForm.IWAppFormShow(Sender: TObject);
begin
IWLabel1.Caption:= Here This ID from function GetId -> 5
end;
(07-17-2019, 08:23 AM)matija Wrote: [ -> ]In javascript I have a function that returns ID. 
I want to read this value from HTML javascript and display it on the Label.

Code:
procedure TMainForm.IWAppFormCreate(Sender: TObject);
begin
  AddToInitProc('function GetId() { return 5; }');
end;

procedure TMainForm.IWAppFormShow(Sender: TObject);
begin
  IWLabel1.Caption:= Here This ID from function GetId -> 5
end;

I'm not exactly sure if I understand your goal here.

I'm supposing that you want to send some data from the browser to the application. The best way to accomplish that is via Async calls (AJAX).

First you need to register a function on server side. We call this function a callback function (because these functions can be called from your JavaScript code).
I'll use one of the IW 15.1 new features and register an anonymous function:


Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  RegisterCallBack('ReceiveID',
      procedure (aParams: TStrings)
      begin
        IWLabel1.Caption := aParams.Values['ID'];
      end
    );
end;


Now, you need to call the ReceiveID function from your JavaScript. The simplest way to do it is via ajaxCall() function, like this:

Code:
ajaxCall("ReceiveID", "&ID=" + GetId());

In the line above you are using function ajaxCall() (which is a IW library helper function) and instructing it to call your function (on your server) named ReceiveID, passing a named parameter as "ID=5".
(07-18-2019, 07:38 AM)Alexandre Machado Wrote: [ -> ]
(07-17-2019, 08:23 AM)matija Wrote: [ -> ]In javascript I have a function that returns ID. 
I want to read this value from HTML javascript and display it on the Label.

Code:
procedure TMainForm.IWAppFormCreate(Sender: TObject);
begin
  AddToInitProc('function GetId() { return 5; }');
end;

procedure TMainForm.IWAppFormShow(Sender: TObject);
begin
  IWLabel1.Caption:= Here This ID from function GetId -> 5
end;

I'm not exactly sure if I understand your goal here.

I'm supposing that you want to send some data from the browser to the application. The best way to accomplish that is via Async calls (AJAX).

First you need to register a function on server side. We call this function a callback function (because these functions can be called from your JavaScript code).
I'll use one of the IW 15.1 new features and register an anonymous function:


Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  RegisterCallBack('ReceiveID',
      procedure (aParams: TStrings)
      begin
        IWLabel1.Caption := aParams.Values['ID'];
      end
    );
end;


Now, you need to call the ReceiveID function from your JavaScript. The simplest way to do it is via ajaxCall() function, like this:

Code:
ajaxCall("ReceiveID", "&ID=" + GetId());

In the line above you are using function ajaxCall() (which is a IW library helper function) and instructing it to call your function (on your server) named ReceiveID, passing a named parameter as "ID=5".

Work! Thx.