Default value to select option menu is not recognized

This question already has an answer here:

  • How can I set the default value for an HTML <select> element? 18 answers

  • If you are using JSP then there is a tag for html-select-dropdown . Using <form:select> tag you can do something like this -

    <form:select path="country">
       <form:option value="NONE" label="--- Select ---"/>
       <form:options items="${yourList}" />
    </form:select>
    

    To know more about how to use jsp select tag dig deep into this link.

    And for assiging default value take help from this answer.

    Update
    This is how you can include JSTL in you JSP

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    
    <html>
        <head>
            <title></title>
        </head>
        <body>
    
        </body>
    </html>
    

    Here you see prefix="form" , you can name the prefix as you want. You can find more detail here.


    The ="selected" part is not necessary. Just <option selected> will do fine.

    <select id="name" class="state">
    <option selected value="Brad">
        Brad
    </option>
    
    <option value="Carol">
        Carol
    </option>
    
    <option value="Derrick">
        Derrick
    </option>
    </select> 
    

    The value, in this case "Brad", would be passed as a string unless another option is selected.

    链接地址: http://www.djcxy.com/p/88078.html

    上一篇: 在AngularJS中为依赖下拉列表选择默认值

    下一篇: 无法识别选择选项菜单的默认值