Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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"
	pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>clock</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
	Current date and time on server
	${requestScope.time}
	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">
		
	</form>
</body>
</html>
Posted
Updated 27-Feb-13 9:43am
v3
Comments
steve3947 28-Feb-13 7:18am    
I just want the listbox to display the option chosen

1 solution

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 :

HTML
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;
        break;
    }
}


Note:Call this method after drop down is list
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900