Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
java script variable access in intraweb
#1
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?
Reply
#2
Hi, you can pass any value from html/js to delphi using new callback functions.
http://docs.atozed.com/docs.dll/developm...015.1.html
Reply
#3
(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/developm...015.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.
Reply
#4
(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/developm...015.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.
Reply
#5
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" );
Reply
#6
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;
Reply
#7
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>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)