Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 2 Jahren, 6 Monaten
Letzter Beitrag:
vor 2 Jahren, 6 Monaten
Beteiligte Autoren:
Fabrice Harari, Viggo Poulsen, Gus

[WB20] How to access global variables or controls from JS code?

Startbeitrag von Gus am 15.08.2015 22:53

Hello All:

I'm working in a Web page [WB20] and using JavaScript code in a Button Click event.
I have to pass a value to a JS function so I have defined a val variable in Javascript, so doing val = 30 or val = 50, everything works fine.

Now, I need the pass the real value which comes from another procedure. I have a global variable defined in W Language but it seems when I do:
val = globalvar doesn't pass the value. In other words, I can't access global variables from the JS code. I tried to use a control to set the values and then take it form the JS code, but I couldn't get access either.

Is there a way to accomplish this?

Thanks in advance
Gus

Antworten:

Hi Gus

One way is to put %1 in your java code instead of the variable. Then you use Stringbuild to put in the real value, and use the final java string.

Please see attached pdf, as I cannot write code directly in this message.

BUT if one could interact directly with a global var, it would be possible to get data the other way, and that is missing in the Stringbuild method. As an example with Gmap, it would be nice to get the actual zoom factor, and the last addressed marker back.

Best regards
Viggo Poulsen
[attachment 1634 PartOfGmap.pdf]

von Viggo Poulsen - am 16.08.2015 08:01
Hi Gus,

Your wlanguage code (browser side) is automatically translated into JS code for execution. As a result, every field and variable declared on the browser side in wlanguage is in fact declared in the page JS code. By default, it is declared with another name (its "alias")...

If I remember correctly, when you hover on a field, the tooltip contains the field alias value (will never change)... So, if in your JS code you do fieldalias=Value, it should work.

I do no know how to get a variable alias, though. So if you really need to use one, you can go in the advanced options of the page/project and use the option telling the compiler NOT to use aliases. When you do that, two things will happen:
- the js code will use the same names than the wlanguage side, allowing you to directly address the variable and fields by their name.
- HOWEVER because of that, it become YOUR RESPONSABILITY to use a variable and field naming convention that respect the JS constraints/rules. IF you do not, your page will not work at all, so that option is reserved for advanced use.

Best regards

von Fabrice Harari - am 16.08.2015 13:18
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.