• Post Reply Bookmark Topic Watch Topic
  • New Topic

select value retaining problem

 
Sanjay Izardar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have 2 files
1) combo.jsp
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
function send() {
document.form1.action = "combotemp.jsp";
document.form1.submit();
}
</script>

</head>

<body>
<form name="form1" >
<p>
Name
<select name="name" onchange="send();">
<option>Ajay</option>
<option>Vijay</option>
<option>Ramesh</option>
<option>Raja</option>
<option>Salim</option>
</select>
</p>
<p> </p>
</form>
</body>
</html>

2) combotemp.jsp
<%
String nm=request.getParameter("name");
response.sendRedirect("Combo.jsp?nm="+nm);
%>

now how to retain the same value in the combo box, that i send in the combotemp.jsp. it always shows its first value after coming from combotemp.jsp.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First - Please use code tags while posting your code. Second - Never use Scriptlets in JSP.

You can do it by setting the "selected" attribute.

Using javascript (dont know if its the optimal solution). you will be able to do it as follows...



you can use this script on your body onload.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!