如何从下拉列表中获取所选值

时间:2014-02-05 05:55:06

标签: html5 jsp

这是我在jsp中编写的代码

<form name="form" method="post" action="example" >
            <select id="sel" name="sel" onclick="sel()"> 
            <% DirectoryReader dir=new DirectoryReader();
            String[] directories=dir.dropDown();%>
                <option value=default>Please Select</option>
                <%for(String direct:directories)
                    {%>
                <option value=<%=direct %>><%=direct%></option>
                <%} %>
            </select>
            </form>
        </li>
    </ul>
    <ul class="filterui">
        <li><label class="filter">Managed Server</label></li>
        <li>
            <select >
                <option>Please Select</option>
                <option></option>
            </select>
        </li>
    </ul>

这是我写的脚本:

<script>
 function sel(){
 var sel = document.getElementById("sel");
 var selectedValue = sel.options[sel.selectedIndex].text;
 document.write(sel);
 document.write(selectedValue); 
 }
</script>

0 个答案:

没有答案