Click here to Skip to main content
Rate this: bad
good
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"
	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 27-Feb-13 10:42am
Edited 27-Feb-13 10:43am
v3
Comments
steve3947 at 28-Feb-13 7:18am
   
I just want the listbox to display the option chosen

1 solution

Rate this: bad
good
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;
        break;
    }
}
 
Note:Call this method after drop down is list
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.150327.1 | Last Updated 28 Feb 2013
Copyright © CodeProject, 1999-2015
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