select all options in html select dynamically

前端 未结 3 1613
误落风尘
误落风尘 2020-12-18 11:07

I have two HTML selects in a form. The first is called available and contains several options:


                        
    
提交评论

  • 2020-12-18 11:31
        <form name="jmxForm" onsubmit="selectAllOptions(sortedby_target)">
        ....
        </form>
    
    
    
    
    
    function selectAllOptions(obj) {
    if (!hasOptions(obj)) { return; }
    for (var i=0; i<obj.options.length; i++) {
        obj.options[i].selected = true;
        }
    }
    
    0 讨论(0)
  • 2020-12-18 11:39
    <input type="submit" onclick="selectAllOptions(sortedby_target);" />
    

    or

    <form onsubmit="selectAllOptions(sortedby_target);"></form>
    

    You can get inspired here: http://demo.redmine.org/projects/asdf/issues when trying to change columns in a table.

    0 讨论(0)
  • 提交回复
    热议问题