0

I need to dynamically select an option from a dropdown on page load. The dropdown is created with Vue.js I am using jQuery to dynamically "click" the dropdown on page load and that is working. However, the content that usually populates below after click is not working. I know the content is also being pulled with Vue but I do not know much about Vue. Is there a way to have an option of the select dynamically selected on page load AND have the content below shown as well.

Here's what I've done in jQuery that is getting the option to be selected on load.

$('select option[value="3"]').attr('selected', true);

Update: I think I've figured out why it's not working but still don't know how to get it to work. Using .val() will not work. The options I'm trying to pre-select won't exist yet, because the request is not fired until the control is opened and/or the user begins searching.

  • It probably relies on a `change` or `input` event to the ` – user7290573 Sep 13 '19 at 22:32
  • Possible duplicate of https://stackoverflow.com/questions/249192/how-can-you-programmatically-tell-an-html-select-to-drop-down-for-example-due – MartinT Sep 13 '19 at 22:57
  • Possible duplicate of [How can you programmatically tell an HTML SELECT to drop down (for example, due to mouseover)?](https://stackoverflow.com/questions/249192/how-can-you-programmatically-tell-an-html-select-to-drop-down-for-example-due) – MartinT Sep 13 '19 at 22:58
  • @user7290573 I tried that but no luck. – McKenzie Ussery Sep 16 '19 at 19:47
  • Most likely, it doesn't work because your code runs before the element has been created. Or maybe you default the value of the dropdown model to `''`. Since you use Vue to generate the dropdown, why don't you simply default the dropdown model to the value of the third option? Also please note without a [mcve] it's impossible to know for sure what code will work in your case, which makes your question not useful for other users and therefore off-topic on [SO]. – tao Sep 16 '19 at 19:59

0 Answers0