java script variable access in intraweb

<< Click to Display Table of Contents >>

Navigation:  Forum >

java script variable access in intraweb

Forum link

 


 

12-11-2019, 01:43 PM:

 

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?

 


 

12-11-2019, 02:43 PM:

 

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

 


 

12-11-2019, 08:10 PM:

 

(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.htmlThe file is written for those who already know a lot about javascript and callback. So not for me who knows nothing about that.

 


 

12-12-2019, 09:51 AM:

 

(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.htmlThe 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.

 


 

12-12-2019, 12:47 PM:

 

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" );

 

 

 


 

12-15-2019, 09:40 PM:

 

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;

 


 

12-15-2019, 10:05 PM:

 

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>