To select the single element, we need to use document.querySelector() method by passing a [data-attribute = 'value'] as an argument. selected Optional The selected value(s) will be bound to the specified model's property if the property is model bound. The return collection of elements is live. If you had an array that has name-value pairs and you wanted to use the index from the array as the value for the options and the array value as the text to display, you could do this: Should you build it from scratch or use third-party library? If no option selected … Method 1: Using the value property: The value of the selected element can be found by using the value property on the select element that defines the list. document.getElementById("form_id").action = action; Example: The selected attribute is a boolean attribute. changing the js function to dynamically create “country” options is not an option. A Boolean that sets the selected attribute value, i.e. the selected attribute is sometimes also written: