How do I programmatically set the value of a select box element using JavaScript?

后端 未结 17 1694
轮回少年
轮回少年 2020-11-22 06:33

I have the following HTML

17条回答
  •  别那么骄傲
    2020-11-22 06:50

    Why not add a variable for the element's Id and make it a reusable function?

    function SelectElement(selectElementId, valueToSelect)
    {    
        var element = document.getElementById(selectElementId);
        element.value = valueToSelect;
    }
    

提交回复
热议问题