Default value to select option menu is not recognized

AndI

Below is the code used for simple html and it works:

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

    <option value="Carol">
        Carol
    </option>

    <option value="Derrick">
        Derrick
    </option>
</select> 

Is there another method that i can use so that I can set a default value to my select option tag?

In my jsp file:

</html:select>
<html:option value="0">--Select--</html:option>
                    <html:option value="Brad" selected="selected">Brad</html:option>
                    <html:option value="Carol">Carol</html:option>
                </html:select>

The <option value="Brad" selected="selected"> Brad </option> works in simple html. Brad is shown before clicking the dropdown arrow. My problem is that when I used this in my jsp it says that "The attribute is not recognized <html:option value="Brad" selected="selected">Brad</html:option>"

Erfan Ahmed

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Issue with select default value of select menu in Jquery?

From Dev

Set default value of select to null option

From Dev

Select Option Value return Integer by default

From Dev

Codeigniter in select option default value not working

From Dev

how to set a default value for select option

From Dev

Select Option Value return Integer by default

From Dev

Default Select Option Based on Input Value

From Dev

Skip select option if default value come

From Dev

The default value is not ? object:null ? in select option Angularjs

From Dev

how to select default value drop down menu

From Dev

Dropdown Menu: onChange, find select id of option value

From Dev

use jQuery to select option from menu based on its text not value

From Dev

CakePHP2 - Default value for input - select with option multiple

From Java

how to use ng-option to set default value of select element

From Dev

Make the default option of select tag to be of current value of name in Rails

From Dev

set default option in a select via ng-init on VALUE and not INDEX

From Dev

Unable to get value of default option in select2 jquery

From Dev

AngularJS - ng-repeat default value for select option

From Java

default select option as blank

From Dev

HTML <select> default option

From Dev

default setting for option select

From Dev

default value in option

From Dev

Dropdown menu default value

From Dev

Android - Programmatically select a menu option

From Dev

Adding new option to select menu

From Dev

AngularJS select creates option with value "? object:null ?" and doesn't use empty default option when bound to null

From Dev

How can I pre-select an option in a select menu based on a value stored in the database?

From Dev

How to save a value to localstorage from a select menu as soon as u select the option? It is not working

From Dev

Laravel - Select - set Default option

Related Related

  1. 1

    Issue with select default value of select menu in Jquery?

  2. 2

    Set default value of select to null option

  3. 3

    Select Option Value return Integer by default

  4. 4

    Codeigniter in select option default value not working

  5. 5

    how to set a default value for select option

  6. 6

    Select Option Value return Integer by default

  7. 7

    Default Select Option Based on Input Value

  8. 8

    Skip select option if default value come

  9. 9

    The default value is not ? object:null ? in select option Angularjs

  10. 10

    how to select default value drop down menu

  11. 11

    Dropdown Menu: onChange, find select id of option value

  12. 12

    use jQuery to select option from menu based on its text not value

  13. 13

    CakePHP2 - Default value for input - select with option multiple

  14. 14

    how to use ng-option to set default value of select element

  15. 15

    Make the default option of select tag to be of current value of name in Rails

  16. 16

    set default option in a select via ng-init on VALUE and not INDEX

  17. 17

    Unable to get value of default option in select2 jquery

  18. 18

    AngularJS - ng-repeat default value for select option

  19. 19

    default select option as blank

  20. 20

    HTML <select> default option

  21. 21

    default setting for option select

  22. 22

    default value in option

  23. 23

    Dropdown menu default value

  24. 24

    Android - Programmatically select a menu option

  25. 25

    Adding new option to select menu

  26. 26

    AngularJS select creates option with value "? object:null ?" and doesn't use empty default option when bound to null

  27. 27

    How can I pre-select an option in a select menu based on a value stored in the database?

  28. 28

    How to save a value to localstorage from a select menu as soon as u select the option? It is not working

  29. 29

    Laravel - Select - set Default option

HotTag

Archive