Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Want simple JS demo
#1
At Huh
Just want to show user time zone offset in IWEdit1.
IW demo seem too complicate that I did not get the right way to handle return.
What am I missing?


procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  Self.JavaScript.Add('function TZoffset(){'+ #13#10
  +'var d = new Date();'+ #13#10
  +'var tn = d.getTimezoneOffset();'+ #13#10
  +'document.getElementById("IWEDIT1").innerHTML = tn;'+ #13#10
  +'}');

IWedit1 is a way for return back the value to usersession variable only.

Thanks for help!
end;
Reply
#2
Really worst documentation. The javascript demo show nothing except .res. Some tell to use hidden component but no detail. Some refer to RegisterCallBack but no JS related. Some telling how to load JS in many way but nothing handle JS data passing by. Is Intraweb always as beta? Forever!

Just a simple question, search for a day without ensure answer.
Reply
#3
Hi Kristy. try this:

Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
   Self.JavaScript.Add('document.addEventListener('DOMContentLoaded', function() {' + sLineBreak +
   'var d = new Date();' + sLineBreak +
   'var tn = d.getTimezoneOffset();' + sLineBreak +
   'document.getElementById("IWEDIT1").innerHTML = tn;' + sLineBreak +
   '})');
end;
Wrong button,  Smile
Reply
#4
I must say that is the best looking PHP code I have ever seen!
Reply
#5
Thanks, but not work.
Reply
#6
That also not work. IW 14 method also not work, everything not work!

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
RegisterCallBack('TZOS',
procedure (aParams: TStrings)
begin
IWEdit1.text := aParams.Values['tn'];
end
);
end;

procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
var
TZJS_str : string;
begin
TZJS_str := 'function TZoffset(){'+ #13#10
+'var d = new Date();'+ #13#10
+'var tn = d.getTimezoneOffset();'+ #13#10
+'return tn;'+ #13#10
+'}';
WebApplication.CallBackResponse.AddJavaScriptToExecute('ajaxCall("TZOS", "&tn=" + TZJS_str)');
end;

Not work...

procedure TIWForm1.IWButton1AsyncClick(Sender: TObject; EventParams: TStringList);
var
TZJS_str : string;
begin
TZJS_str := 'function TZoffset(){'+ #13#10
+'var d = new Date();'+ #13#10
+'var tn = d.getTimezoneOffset();'+ #13#10
+'document.getElementById("IWEDIT1").innerHTML = tn;'+ #13#10
+'}';

WebApplication.CallBackResponse.AddJavaScriptToExecute(TZJS_str);
end;
Reply
#7
Hi Kristy, please, try this:
Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
   Self.JavaScript.Add('document.addEventListener("DOMContentLoaded", function() {' + sLineBreak +
   'var d = new Date();' + sLineBreak +
   'var tn = d.getTimezoneOffset();' + sLineBreak +
   'document.getElementById("IWEDIT1").value = tn;' + sLineBreak +
   '});');
end;
I made a demo for you.


Attached Files
.zip   Kristy.zip (Size: 56.79 KB / Downloads: 11)
Reply
#8
(08-17-2019, 09:38 PM)Jose Nilton Pace Wrote: Hi Kristy, please, try this:
Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
   Self.JavaScript.Add('document.addEventListener("DOMContentLoaded", function() {' + sLineBreak +
   'var d = new Date();' + sLineBreak +
   'var tn = d.getTimezoneOffset();' + sLineBreak +
   'document.getElementById("IWEDIT1").value = tn;' + sLineBreak +
   '});');
end;
I made a demo for you.
Thanks Jose, I just make a new project with indy, copy and paste your code only. Result is nothing show. I also having copy and paste problem while Delphi IDE loaded, and others. Today, I would try to reinstall Delphi in fresh. Hope would solve the unknown problem.Thanks for your help!A bit ask, is your code can return the IWedit1.text value to back-end variable ?
Reply
#9
(08-17-2019, 09:38 PM)Jose Nilton Pace Wrote: Hi Kristy, please, try this:
Code:
procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
   Self.JavaScript.Add('document.addEventListener("DOMContentLoaded", function() {' + sLineBreak +
   'var d = new Date();' + sLineBreak +
   'var tn = d.getTimezoneOffset();' + sLineBreak +
   'document.getElementById("IWEDIT1").value = tn;' + sLineBreak +
   '});');
end;
I made a demo for you.

Fresh reinstalled, your code is work a part. but the IWedit.text cannot pass the value to variable anymore.
Reply
#10
Hi Kristy,

I downloaded the demo Jose provided and tried it here, it works fine. I'm running IW 15.1.2, just haven't installed 15.1.3 yet, but that shouldn't matter.

If you run the demo, exactly what are you seeing?
Run the demo, you should see a button and textbox. Textbox will contain the default text "IWEdit1".
When you press the button it will execute the callback, replacing the "IWEdit1" with "something", and also show the notification.

Where does your execution break down?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)