Jump to content

retun value from JS to local variable


wkotze

Recommended Posts

sorry Sherzod, examples not clear.

i am trying to display both the server time and the local time to thuser

procedure TMainmForm.lbltimeClick(Sender: TObject);
var servertime,devicetime : string;
begin
...

  servertime  := formatdatetime('hh:mm:ss',now)

// javascript call to put local time into 'jsdatestr'
// UniSession.AddJS(' var ldate = new Date(); var jsdatestr  = ldate.toLocaleTimeString("EN-us").substring(0,8); ');  <-- is UniSession.AddJS event the correct  call ?

  devicetime :=  ???  <--- i need jsdatestr  from JS above here

  uniGUIDialogs.ShowMessageN( 'server time is ' +  servertime + ', your local time is ' + devicetime )

...
end  

 

Link to comment
Share on other sites

13 minutes ago, wkotze said:

yes

1. UniButton1.ClientEvents.ExtEvents ->

function click(sender, e, eOpts)
{
    ajaxRequest(sender, 'getLocalTime', ['time='+new Date().toLocaleTimeString()]);
}

2. UniButton1.OnAjaxEvent ->

procedure TMainForm.UniButton1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = 'getLocalTime' then
  begin
    (Sender as TUniButton).CustomAttribs.Values['clienttime'] := Params.Values['time'];
  end;

end;

3. UniButton1.OnClick ->

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  ShowMessage((Sender as TUniButton).CustomAttribs.Values['clienttime'])
  
end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...