user3872752
user3872752

Reputation: 35

how to show 2 elements tied together in one dropdown list

This works with 2 tables userName and userID. Example: I have id =1 and name =x.

I have a drop down list and it will show accordingly.

User - [x]

UserManager mgr = new UserManager();
ArrayList<User> users = mgr.retrieveAllUser();
for (User user : users)
{
    out.print(String.format("<option value=\"%s\" label=\%s\">",user.getUserID(), user.getUserName()));
    out.print(user.getUserID() + user.getUserName());
}

How do i make it so that it shows:

User - [1 - x]

^meaning i wish to get id + "-" + name, all in one option

Upvotes: 1

Views: 61

Answers (1)

user2575725
user2575725

Reputation:

Html option tag is not valid, you are missing the closing tag:

out.print(String.format("<option value='%s'>%s - %s</option>",user.getUserID(), user.getUserID(), user.getUserName()));

EDIT

Here there are three place-holders presented by %s, for each place holder we are supposed to pass its value, does not matter if the value gets repeated.

value='%s' - user.getUserID()

%s - %s - user.getUserID(), user.getUserName()

Upvotes: 1

Related Questions