• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 656
  • Last Modified:

JSP ComboBox

Hi I have jsp that have a combo box with 3 options,

Option1
Option2
Option3,

I,m sending some values of a DB to that JSP. I have a column that need to match that JSP comboBox.

Let said that in the database the user save the value Option2, i want to fill the ComboBox with the value that is in the database, but i also want that the user have the oportunity to choose one of the 2 others options.

If need more details let me know
Thanks
0
cano63
Asked:
cano63
1 Solution
 
VenabiliCommented:
I am not sure I understand what problem you do have exactly...
0
 
Pramod KumarCommented:
Try this:
<%
	//reading data from db
	String fromDB = request.getAttribute("fromDB");
%>

<select name="city">
	<%if (fromDB.equals("Option1")) {%>
		<option selected value="Option1" selected>Option1</option>
	<%}
	else 
	{%>
		<option selected value="Option1">Option1</option>
	<%}%>

	<%if (fromDB.equals("Option2")) {%>
		<option selected value="Option2" selected>Option2</option>
	<%}
	else 
	{%>
		<option selected value="Option2">Option2</option>
	<%}%>

	<%if (fromDB.equals("Option3")) {%>
		<option selected value="Option3" selected>Option3</option>
	<%}
	else 
	{%>
		<option selected value="Option3">Option3</option>
	<%}%>

</select>

Open in new window

0
 
cano63Author Commented:
I founf it

<option value="financial" <%= auto.getFinancigMethod().equalsIgnoreCase("financial")?" selected":""%>>Financial</option>
Thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now