Get a Javascript variable outside the script

Hello, I’ve been reading community post about variables and javascript using Wappler, but although I try, cannot achieve my goal.

I need to get a Javascript variable outside the script to Wappler. I’ve created a variable using Wappler, but now I need Javascript to set that Wappler variable.

The script is the following, there are in fact two values I need to set to two different Wappler Variables, “vuFp” and “bfpSeed”. The div I got from the developer, were the variable is shown because of the div id, works fine, but I need to the variable to be accesible to be used afterwords on serverconnect.

<script>
	var vuFp = new VUBrowserFP();  
	vuFp.getFingerprintInfo(function( info ){         
	         var result =  info.fingerprint; //Informaci�n a enviar al server en Base64              			 	
			 
			 var element = document.getElementById("bfp");
			 
			 element.innerHTML = result;
			 
	});  


	
	vuFp.getFingerprintInfoWithSeed(function( info ){         
	         var result =  info.fingerprint; //Informaci�n a enviar al server en Base64              			 	
			 
			 var element = document.getElementById("bfpSeed");
			 
			 element.innerHTML = result;
	});  

</script>

Thanks!!

1 Like

example usage ;

 <script>
        function myFunction() {
            var car = {type:"Fiat", model:"500", color:"white"};
            dmx.app.set('car', car);
         }		
    </script>

I’ve read it completely, but since i’m not a JS coder I cannot make it work with my script. I could if I need to set a variable from wappler to the script, but not the other way around

Wappler variables can be accessed using dmx.app.data. Assuming the variable is at the root of your page, then:

dmx.app.data.vuFp.value

I’ve wrote this:

<dmx-value id="myVariable" dmx-bind:value="dmx.app.data.vuFp.value"></dmx-value>

But didn’t fetch the variable from the JS

What I provided is when you need a wappler variable within javascript

If your variable is not in the root of your page, then you have to use this method suggested by patrick

Try typing dmx.app.data.vuFp.value in your browser console, if it comes with undefined, then probably it’s nested in your page…

It’s the other way around. I need to get the varible from the JS not inside the JS.

Doesn’t Serhat’s solution work for you?

You add a variable component in your page, set the value of the same from JS like this:

dmx.parse(‘var_test.setValue(‘12345’)’);

If your variable is not in the root, you must use the full path like this:

dmx.parse(‘repeat1.items[7].var_test.setValue(‘12345’)’);

and use the variable within your page as usual.

I’ve already tried that before and didn’t work.

Nothing

The single quote at the end is too curved, try editing it in wappler, usually happens when you copy paste it from other editors.

Also if vuFp was in fact a string, then enclose it within single quotes.

Now I get this:

What do you get if you type dmx.app.data.myVariable in your browser console?

Nothing:

I’m getting this error:

You have type next to the >

I get: {$type: “value”, value: null, __setValue: ƒ}

Is app connect framework added on your page?
Are you sure you know how the things work? Do you have any basic js knowledge?

Now type, dmx.parse('myVariable.setValue("vuFp")'), press enter

Then, check the variable’s value again by running, dmx.app.data.myVariable