I want to specify the value of a select
directly (instead of through option
)
#57
aarongustafson
started this conversation in
Wants
Replies: 2 comments 1 reply
-
Tagging @gregwhitworth as this might align with work being done in Open UI. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Consider this HTML code:
Browsers are supporting assigning value to the
select
element directly through thevalue
attribute in JavaScript. For example, to set the value "opt 2" selected in theselect
element, we can write as following in JS:This code will select the 2nd option. However, presently the
value
attribute can not be set directly through HTML as following:This is particularly useful on server side. There, a developer has to implement a loop to match all the
option
elements and append theselected
attribute to the selectedoption
element. For example, in PHP, if $day has value "Friday" and developer wants to specify anoption
asselected
which has "Friday" as its value, then they need to do this:The above code will output as following (
selected
attribute in "Friday"option
):But it should be possible as following too:
The above code will output as following, and the
option
having value "Friday" should be selected by default:https://webwewant.fyi/wants/5ee43a1fc66658f802c8b2cb/
Beta Was this translation helpful? Give feedback.
All reactions