Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value change of select does not affect visuals #6632

Closed
ghost opened this issue Mar 24, 2021 · 2 comments
Closed

Value change of select does not affect visuals #6632

ghost opened this issue Mar 24, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 24, 2021

Problem

Changing selected value of a <select> with Javascript does not change the visual selection.

I am using Javascript to change a selected value of a <select>, getting the select element by id and setting it's value to a different option value.
This works just fine, but the visual selection in the select input-field does not change. Clicking afterwards on it, shows the new selected value and will then display it correctly in the input-field.

Is it possible to change the visual selection, if the selected value changes programmatically? For my usecase, I need to show the change of the selection immediately.

Reconstruction:

CodePen

@jshster
Copy link

jshster commented Mar 24, 2021 via email

@ghost
Copy link
Author

ghost commented Mar 24, 2021

Simply call the formSelect() method again after setting the value programmatically. That should do the trick.

Thanks! This did the trick. I just found out that the "onchange" event does not fire and this seems to be the problem of javascript.

@ghost ghost closed this as completed Mar 24, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant