Click here to Skip to main content
12,550,111 members (47,950 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java
DropDownList to show the item I selected in the list. I get it to serve the page with a request response
but it goes to the default I was hoping if someone could show me how to make the list show the Item I picked.
PS. I'm very new to programing so could you please explain what is going on as well
This is my code
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
<%@taglib prefix="c" uri=""%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	Current date and time on server
	Use this form to select another format
	<form action="${pageContext.request.contextPath}/clock" method="post">
		Select format <select name="format">
			<option value="full" selected>full</option>
			<option value="long" selected>long</option>
			<option value="medium" selected>medium</option>
			<option value="short" selected>short</option>
			<option value="bad">bad</option>
		</select> and click <input type="submit" name="getTime" value="Get Time">
Posted 27-Feb-13 9:42am
Updated 27-Feb-13 9:43am
steve3947 28-Feb-13 7:18am
I just want the listbox to display the option chosen

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If I understood properly, then you want to set the drop down list whatever you select before sending the request.
In that case you have to return back the selected option in response and do the following :

var textToFind = 'medium';//value read from scope variable
var dd = document.getElementById('formatId');
for (var i = 0; i < dd.options.length; i++) {
    if (dd.options[i].text === textToFind) {
        dd.selectedIndex = i;


Note:Call this method after drop down is list

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100