Atozed Forums
java script variable access in intraweb - 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: java script variable access in intraweb (/thread-1429.html)



java script variable access in intraweb - MrSpock - 12-11-2019

How can I define java script variables in any way so I can set their values in java script and to have access to read the variables in intraweb 15.1.5?


RE: java script variable access in intraweb - Jose Nilton Pace - 12-11-2019

Hi, you can pass any value from html/js to delphi using new callback functions.
http://docs.atozed.com/docs.dll/development/Async%20callbacks%20in%20IntraWeb%2015.1.html


RE: java script variable access in intraweb - MrSpock - 12-11-2019

(12-11-2019, 02:43 PM)Jose Nilton Pace Wrote: Hi, you can pass any value from html/js to delphi using new callback functions.
http://docs.atozed.com/docs.dll/development/Async%20callbacks%20in%20IntraWeb%2015.1.html
The file is written for those who already know a lot about javascript and callback. So not for me who knows nothing about that.


RE: java script variable access in intraweb - MrSpock - 12-12-2019

(12-11-2019, 08:10 PM)MrSpock Wrote:
(12-11-2019, 02:43 PM)Jose Nilton Pace Wrote: Hi, you can pass any value from html/js to delphi using new callback functions.
http://docs.atozed.com/docs.dll/development/Async%20callbacks%20in%20IntraWeb%2015.1.html
The file is written for those who already know a lot about javascript and callback. So not for me who knows nothing about that.
Will the below work?

My strategy would be something like this:
I define an IWLabel on the form, let's suppose its name is IWLabel1.
I make it visible:=false. and form.renderInvisible:=true
I add code to my javascript function such that it changes the value (label's
tag in this case) of the component  something like:
document.getElementById("IWLABEL1").tag='34';

Now I click a button and hope to get the changed tag value in intraweb back-end.


RE: java script variable access in intraweb - Jose Nilton Pace - 12-12-2019

Hi. Some JS have an AJAX call internally or after finished, call a callback delphi function.

First example is a JS Select2 calling an internal AJAX:
Code:
  $('#Select2').select2({
    ajax: {
      url: "$/callback?callback=My_Delphi_CallBack_IW15.1+",
    },

Second example is a JS SweetAlert calling an ajaxcall after the result:
Code:
function SweetAlert() {
  swal({
    type: "question",
    title: "Confirm etc !",
    showCancelButton: true,
    allowOutsideClick: false
  }).then((result) => {
    if (result.value) {
      ajaxCall( "My_Delphi_CallBack_IW15.1+", "" );
    }
  })
}

Third, try changed values to get in a post.
Code:
document.getElementById("IWLABEL1").tag='34';
AddChangedControl( "IWLABEL1" );



RE: java script variable access in intraweb - MrSpock - 12-15-2019

Now I see, I need to call back-end from IWImage click or mousedown, but it does not work so another idea. But I think this will not work without ajax. How to change the code? I need to get coordinates of the clicked point on IWImage.

IWImage.extraTag: id="FOTOGRAFIA"

IWForm
extraHeaders

<script>
document.getElementById("FOTOGRAFIA").addEventListener('click', getPosition)

function getPosition(e) {
  var rect = e.target.getBoundingClientRect();
  var x = e.clientX - rect.left;
  var y = e.clientY - rect.top;
  return { x, y }
}
</script>


procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  RegisterCallBack('getPosition)',
      procedure (aParams: TStrings; out aResult: string)
      var
        x, y: Integer;
      begin
        x := StrToIntDef(aParams.Values['x'], -1);
        y := StrToIntDef(aParams.Values['y'], -1);
        // do something with x and y
      end
    );
end;


RE: java script variable access in intraweb - Jose Nilton Pace - 12-15-2019

I think you do something like this:
Code:
<script>
document.getElementById("FOTOGRAFIA").addEventListener('click', getPosition)

function getPosition(e) {
  var rect = e.target.getBoundingClientRect();
  var x = e.clientX - rect.left;
  var y = e.clientY - rect.top;
  ajaxCall( "My_Delphi_getPosition", "x=" + x + "&y=" + y );
}
</script>