wood burning stoves*
The moose likes JSP and the fly likes Selection Drop Down Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Selection Drop Down Question" Watch "Selection Drop Down Question" New topic
Author

Selection Drop Down Question

Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
I am having trouble capturing a value from a select drop down list in a page where the user has multiple choices and the page sends back the city, state, zip, and a list of plans. The problem is that the city, state and zip are captured, but if the user selects any row other than the first, the drop down list values does not get captured. Here is my code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@include file="HeaderDirectives.jsp" %>
<html>
<head>
<title>Enrollment:ZipCodeList</title>
<link rel="StyleSheet" href="styles/csstemplate.css" type="text/css" media="screen">
<script language="JavaScript" type="text/JavaScript">
<!--
function submitForm(temp)
{
document.form.action.value = temp;
submit();
}

function submitForm1(temp, zip, town, usState)
{
document.form.action.value = temp;
document.form.zipcode.value = zip;
document.form.city.value = town;
document.form.state.value = usState;
submit();
}

function MM_preloadImages()
{ //v3.0
var d=document;

if(d.images)
{
if(!d.MM_p)
d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0)
{
d.MM_p[j]=new Image;
d.MM_p[j++].src=a[i];
}
}
}
//-->
</script>
<style type="text/css">
body
{
background-image: url("images/BKG_Stripes50%25.gif");
}
</style>
</head>
<body>
<table width="790" height="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#707277">
<tr>
<th valign="top" scope="col" nowrap bgcolor="#ffffff">
<table width="790" border="0" cellpadding="0" cellspacing="0">
<tr>
<th width="790" valign="top" scope="col" nowrap><img
src="images/Web_Banner_01.gif" width="610" height="75" alt=""><img
src="images/Web_Banner_02.gif" width="180" height="75" alt=""></th>
</tr>
</table>

<table width="100%" height="525" border="0" cellpadding="10" cellspacing="0">
<tr>
<th valign="top" scope="col" background="images/BKG_Stripes1805.gif">
<table width="100%" height="31" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th width="739" align="right" valign="middle" scope="col"
bgcolor="#ffffff"> </th>

<th width="31" align="right" valign="bottom" scope="col"><img
src="images/Top_Rgt_Corner.gif" width="31" height="30" alt=""></th>
</tr>
</table>

<table width="770" height="450" border="0" cellpadding="10" cellspacing="0" bgcolor="#ffffff">
<tr>
<td valign="top" nowrap>
<P> </P>
<P> </P>
<fieldset><legend>Zip Code Information</legend>

<form name='form' method="post" action="enroll.do">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="ERROR"/>
<INPUT TYPE="HIDDEN" NAME="zipcode" VALUE="-1"/>
<INPUT TYPE="HIDDEN" NAME="city" VALUE=" "/>
<INPUT TYPE="HIDDEN" NAME="state" VALUE=" "/>
<table border="2" cellpadding="2" cellspacing="2">
<tr>
<th bgcolor="#ffe7c6"></th>
<th bgcolor="#ffe7c6">City</th>
<th bgcolor="#ffe7c6">State</th>
<th bgcolor="#ffe7c6">Zip</th>
<th bgcolor="#ffe7c6">Available Plans</th>
</tr>
<c:forEach items='${CityList}' var='item'>
<tr>
<td>
<input class="submit-button" type="submit" value="select"
onKlick='submitForm1("GOTO_ENROLLMENT_FORM", <c ut value='${item.zipCode}'/>,
"<c ut value="${item.city}"/>", "<c ut value='${item.state}'/>")'>
</td>
<td>
<%-- Available City --%>
<c ut value='${item.city}'/>
</td>
<td>
<%-- State --%>
<c ut value='${item.state}'/>
</td>
<td>
<%-- Zip --%>
<c ut value='${item.zipCode}'/>
</td>
<td>
<%-- Available Plans --%>
<SELECT class="input-box" name="SelectPlanID">
<OPTION value=" ">Select Plan</OPTION>
<c:forEach items='${PlanList}' var='item2'>
<OPTION value="<c ut value='${item2.contractID}'/>" >
<c ut value='${item2.planName}'/>
</OPTION>
</c:forEach>
</SELECT>
</td>
</tr>
</c:forEach>
</table>
<br>
<input class="submit-button" type="submit" value="cancel" ONKLICK='submitForm("GOTO_ZIP_CODE_SEARCH")'></input>
</form>
</fieldset>
</td>
</tr>
</table>

<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
<tr>
<th scope="col" width="31" align="left"><img
src="images/Btm_Lft_Corner.gif" width="31" height="30" alt=""></th>

<th scope="col" width="739" align="right" bgcolor="#ffffff">
    </th>
</tr>
</table>
</th>
</tr>
</table>
</th>
</tr>
</table>
</body>
</html>

Any Ideas? Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

When something like this happens, the first thing to check out is to make sure that the HTML that you are sending to the page is properly formatted. When the form displays, perform a View Source to make sure that the select element and its options are correctly formatted.

If they are, then we'll probably need to see the code that you are submitting the form to.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

P.S. When posting code, be sure to enclose the code in UBB code tags (the CODE button) and be sure to check the 'disable smilies' box to keep your tags from looking so surprised.
Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
Sorry about that.

I looked at the generated code and this is what it looked like, looks fine to me, but then again always nice to have a second opinion.



Here is the handler code as well. Thanks in advance for your help!

Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
You seem to have two drop-downs with the same name in the same form. Is that intentional? If it is, you'll get two parameters with the same name when the form is submitted, and will need to use request.getParameterValues() to get both values.

-Yuriy
Chris Cornelius
Ranch Hand

Joined: Aug 02, 2005
Posts: 48
Yes it was the intention to have more than one drop down on the page.

Thanks, that did the trick.

Chris
 
Consider Paul's rocket mass heater.
 
subject: Selection Drop Down Question
 
Similar Threads
doesnt display struts tags in normal html form
Can not Populate the form on combo box change
Getting search results on same search page
Struts IE render problem
inserting data to a table