How to access variables from JavaScript

if i add app connect variable to my page, how can i access the variable value and how to change the value in javascript?
i have this now but im sure there is better way
var.dmxComponent.data['value']

No one know? :sweat_smile:
i need to do some jquery in my page and want to use wappler variables since its also accessible in dynamic events.

What are you trying to achieve exactly? :slight_smile:

i want to check if the variable value is equal to true then execute some javascript code. then set the value to false after the javascript code is executed

the javascript is for a code reader library

We don’t provide an interface to access the data directly, but if you want to do it then the app data is accessible under dmx.app.data. I would advice to not change the data directly there, but it is okay to read the data from there.

If you want to exchange data I would advice to use a hidden field, you can access it with App Connect and with jQuery. If you change the value with jQuery you also have to trigger a change event on the input to let App Connect know that it is updated.

1 Like

I have a jquery datepicker that works well accept when inserting values into input fields, app connect does not pick up the change. Code for changing field based on date selection looks like this:

$(‘input[name=“datefilter”]’).on(‘apply.daterangepicker’, function(ev, picker) {
$(’.end’).val(picker.endDate.format(‘YYYY/MM/DD’));
});

Based on @patrick feedback I created a variable in app connect and want to insert the end date value into that variable. Tried this without success:

$(‘input[name=“datefilter”]’).on(‘apply.daterangepicker’, function(ev, picker) {
$(‘dmx.app.data.var_biddate’).val(picker.endDate.format(‘YYYY/MM/DD’));
});

Am I missing the logic completely?

if you have a hidden field with the id var_biddate, then you can access it with jQuery like $('#var_biddate').val(picker.enDate.format('YYY/MM/DD').trigger('change'). I added the change trigger to let App Connect know that the value was changed.

1 Like

@patrick aaahhh! that change trigger is the thing I’m looking for, thanks!

2 Likes