Search code examples
htmljsptagshtml-select

Is it possible to dynamically select a certain option from a select menu in a JSP page?


I have a list of records displayed on a JSP page. The user then can click an 'edit' link to modify any part of those records. when they click the edit link they are taken to a different JSP page that has all of the input fields for the record (name, rating, price, etc). the problem is that one of the fields is a select option menu. How can i dynamically set this select menu to the correct option? its easy for the text fields because its just

  value="<%=title%>"

but idk what to do for the option menu. help?


Solution

  • You need to compare the passed data with your data set in that page.

    Do something like this

    Run a loop. Check

    if(passedValue==thisValue)
       <option selected=\"selected\"><%=your value%></option> 
    else
       <option><%=your value%></option>