#Can't get the value from options_for_select

7 messages · Page 1 of 1 (latest)

warm crescent
#

Hey there!

<%= options_for_select(["Size": ["XS", "S", "M", "L", "XL"]], nil) %>

I have this line inside my html to make a select menu with those options, i was wondering how can i get the value of 1 option to a function?

Wrong Example :

 <%= get_value (options_for_select(["Size": ["XS", "S", "M", "L", "XL"]], nil)) %>

Any thoughts how can i do that? Thank you 🙂

fringe rune
#

Can you expand on what you're trying to achieve? I'm not sure I understand the question
options_for_select will generate some html, right? And you pass the values as arguments so it can generate that.
So what do you mean by "get the value of 1 option to a function"? If you want to know what the user selected, you'd have to submit the form and get the value from the body params. Or use an event if you're using liveview, it's hard to tell without more context

warm crescent
fringe rune
#

It depends, are you using regular phoenix "dead" views? lieview? what do you want to do with the value?

warm crescent
#

i'm using a liveview, and i want to use it on my index.ex with the option value

fringe rune
#

then you can either listen for the form submit event and get the value from the form params that you receive in the event handler, or use a phx-change event and listen to that to know what the user selects when they select it