Your problem is that as soon as one option is selected, all of the
following options will be marked as selected. This is because you set
select5 = " SELECTED" and never set it back to "".
Tim
--- Scott Douglass <[EMAIL PROTECTED]> wrote:
<HR>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I've got a form with a lot of elements in it. The elements of this form
have certain attributes specified based on parameters in the request
object.
<p>For example (I hope people won't object to HTML in mail...):
<p><tt><nobr><SELECT NAME="sortby"></nobr></tt>
<br><tt><nobr><%</nobr></tt>
<br><tt><nobr> String select5 = "";</nobr></tt>
<br><tt><nobr> String[] sort = {"ASC", "DESC"};</nobr></tt>
<br><tt><nobr> for (int i = 0; i < 2; i++) {</nobr></tt>
<br><tt><nobr> String sb = (String) sort[i];</nobr></tt>
<br><tt><nobr> if
(sb.equals(request.getParameter("sortby")))</nobr></tt>
<br><tt><nobr> {</nobr></tt>
<br><tt><nobr> select5 = "
SELECTED";</nobr></tt>
<br><tt><nobr> }</nobr></tt>
<br><tt><nobr> %></nobr></tt>
<br><tt><nobr> <OPTION
VALUE="<%=sb%>"<%=select5%>><%=sb%></OPTION></nobr></tt>
<br><tt><nobr> <%</nobr></tt>
<br><tt><nobr> }</nobr></tt>
<br><tt><nobr>%></nobr></tt>
<br><tt><nobr></SELECT></nobr></tt>
<p>The first time the jsp is run (there's no data in the request object),
it acts as expected. Neither of the <OPTION> have the SELECTED
attribute.
The second time this page is loaded (by submitting the form) there is now
request data, and the SELECTED attribute is correctly applied to the
selected
option. However, on the 2nd time the form is submitted, with the other
option selected, BOTH <OPTIONS> end up with the SELECTED attribute!
<p>How can this be? The code clearly says that only the option that was
stored in the request object should have the selected attribute. I can't
figure this out.
<p>All of my <SELECT> widgets on this form (there's five of them) have
this problem. In every case, no matter how many <OPTION> there are,
I always end up with TWO of them having the SELECTED attribute.
<p>I'm using Resin 1.1b3 as my Servlet/JSP engine, Apache 1.3.9 as my
httpd,
Solaris 2.7 on UltraSPARC as my os/server. I know that the parameters of
the request object have the correct values, despite what shows up in the
HTML the client sees, as I'm printing out the SQL query I'm building on
the page each time it loads.
<p>Here's the source, as seen from the client (IE5):
<p>1. First time the page is loaded
<br><tt><SELECT NAME="sortby"></tt>
<br><tt> <OPTION VALUE="ASC">ASC</OPTION></tt>
<br><tt> <OPTION VALUE="DESC">DESC</OPTION></tt>
<br><tt></SELECT></tt>
<p>2. Second time through after submitting the form with DESC selected
<br><tt><SELECT NAME="sortby"></tt>
<br><tt> <OPTION VALUE="ASC">ASC</OPTION></tt>
<br><tt> <OPTION VALUE="DESC" SELECTED>DESC</OPTION></tt>
<br><tt> </SELECT></tt><tt></tt>
<p>3. Third time, submitting the form but selecting the ASC <OPTION>
<br><tt><SELECT NAME="sortby"></tt>
<br><tt> <OPTION VALUE="ASC" SELECTED>ASC</OPTION></tt>
<br><tt> <OPTION VALUE="DESC" SELECTED>DESC</OPTION></tt>
<br><tt></SELECT></tt></html>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
=====
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html