Accessing Javascript values defined in assets/js/app.js in Elixir

You wont be able to directly access the javascript values in Elixir, you need to send them over some bridge. There are a few ways you might approach this. Your QR library will have some way to run a javascript function when a QR code is recognised and this function will all most certainly receive the data that was embedded in the QR code.

In this callback you might:

a) Make a HTTP request in JS to a controller-action that returns data from your records. Your JS should then process the results and update the page for the user. Most commonly this data is returned as JSON.

Things you may want to look into: json, rest api and see Using the Fetch API - Web APIs | MDN which has some example JS code, as well as searching for phoenix rest api.

b) Redirect to a URL with your QR result embedded in the URL. So if your QR code decodes to dogs, you might redirect to https://myapp.com/search?q=dogs to search for dogs, or if it decoded to a record id 100, you might redirect to https://myapp.com/blog/100. This can be as simple as

window.location.href = `https://myapp.com/${qrdata}`;

c) Use the QR data to set values in a regular HTML form and submit it. This an be useful if you have an existing form on the page and the QR code is a “shortcut” to some results from that form.

Good luck. Try making all 3 options.