winsalva
Hello, i want to know how can i possibly access/get Javascript values defined in assets/js/app.js into my Elixir code?
Example, in assets/js/app.js file..
var x = "hello"
What i want to happen or trying to accomplish is access this variable x’s value and pass it as parameter to my Elixir code defined in lib/app/test.ex.
Example Elixir code would be,
def my_function(x_value_here) do
. . .
end
Any suggestion would be really appreciated. Thanks in advance ![]()
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
soup
You might need to give more specific information on your goal, and whether youre using liveview or normal views and when you want to access the value.
winsalva
Hello sir, thank you for the response.
I am just using ordinary view.
What i’m currently doing here is i want to add a qr code scanner on my personal website (for test purposes only) and im using a Javascript library.
Now the Javascript code that reads and decodes the qr code was defined in assets/js/app.js file. I would want to access this result in my Elixir code so i can use it to scan for records in my database.
soup
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 apiand 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 tohttps://myapp.com/search?q=dogsto search for dogs, or if it decoded to a record id100, you might redirect tohttps://myapp.com/blog/100. This can be as simple asc) 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.
winsalva
Thank you so much sir. I really appreciated your efforts! This are really very helpful to me
LostKobrakai
I’d also add using channels and/or liveview to the list of options you could use to send the value to the server for processing.
winsalva
Noted sir. Thank you
dev234
Would you mind explaining this further please? I have the same issue as the OP and am still new to elixir/phoenix. I’m using Surface UI if it helps to mention that. Thank you