File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes pre-selecting values in a select list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "pre-selecting values in a select list" Watch "pre-selecting values in a select list" New topic

pre-selecting values in a select list

Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
Hi all,
I have 2 pages , say page1.jsp and page2.jsp , i am getting some values from user as input in page1 and after pressing the submit button in page1.jsp, it goes to page2.jsp . In page2.jsp, i am getting these values input by user using a request.getParameter(). page2.jsp has many select lists. Depending on the values the user input in the page1, the select list has to be set to that initial values. For example, there is a select list named "letter type" with values type1 , type2, type3 . If the user selected type2 in the page1, then in page2 the "letter type" select list has to be pre-selected to type2 automatically. Also, I am initialising the "letter type" select list from a javascript file that is included in the page, i mean i dynamically generate the select list.
Can anyone tell me how to pre-select values in the select list. I know if we set the selected property of the option to "selected" it would work, but how to do this based on the user input??
Please let me know how to do this.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You would have to get the value of the form passed to the next page via query string of some other method. The you when the javascript is dynamically making the dropdown, then you have to make the selected property true when the values match the information that was passed.
What do exactly want?
Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
Thanks Eric, I did this using the URL search string. This link helped me to do this easily:
I agree. Here's the link:
subject: pre-selecting values in a select list
It's not a secret anymore!