I am looking for a way to set "selectBox" be selected when selectedIndex is unknown

I would like to set YYYY-MM-DD(that comes from GET parameter)

I can set it by .selectedIndex When selectedIndex is unknown... How can I set the default selected box ? I would like to set "the default selected" by value

f.g GET = 2021-08-06 I want it to be selected 2021-08-06 but HTML changes dynamically.

document.getElementById("select_date").selectedIndex = 1; => 2021-07-30 will be sleeted.

        var param = decodeURIComponent(element[1]);

        document.getElementById("select_date").value = param;
        console.log("param"+param)
//log result = param2021-7-23


 <form method="GET" action="http://">
 <select id="select_date" name="delivery_date">
<option value="2021-07-23">2021-07-23</option>
<option value="2021-07-30">2021-07-30</option>
<option value="2021-08-06">2021-08-06</option>
</select>


Read more here: https://stackoverflow.com/questions/68464237/i-am-looking-for-a-way-to-set-selectbox-be-selected-when-selectedindex-is-unkn

Content Attribution

This content was originally published by conny at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: