passing checkbox values between jsps

I have a problem passing checkbox values from one jsp to the next.

This bit works for the first jsp - The piece of code below creates a check box and populates it with the value "uiaddress" from the database, this is a boolean field. I wish to check or uncheck this value according to whether the customer wishes to receive publicity emails.

boolean uiaddress = false;

uiaddress = SQLResult.getBoolean("uiaddress");

<%

String checked;

if (uiaddress)

checked="CHECKED";

else

checked="UNCHECKED";

StringBuffer box=new StringBuffer();

box.append ("<input type=\"checkbox\"name=\"" +uiaddress+ "\" value=\"yes\" "+ checked + ">");

%>

<%= box.toString()%>

I have been using the following piece of code in the second jsp;

String checked = request.getParameter("uiaddress");

I can't seem to make it bring this value in.

I then want to go ahead, update the database with the new value and display a read only checkbox on the page showing what it was set to in the previous jsp.

Any help would be greatly appreciated.

[1186 byte] By [CchrisN] at [2007-9-26 3:25:02]
# 1
Have you tried passing the values through the URL?
Sconnors at 2007-6-29 11:45:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi:

Does the problem happen when the checkbox is not checked on the first jsp page? Browsers do not pass a check box parameter in the http request unless it is checked. Not sure if this is the problem that you are encountering.

Ajay

> I have a problem passing checkbox values from one jsp

> to the next.

>

> This bit works for the first jsp - The piece of code

> below creates a check box and populates it with the

> value "uiaddress" from the database, this is a boolean

> field. I wish to check or uncheck this value according

> to whether the customer wishes to receive publicity

> emails.

>

>

> boolean uiaddress = false;

>

> uiaddress = SQLResult.getBoolean("uiaddress");

>

>

> <%

&gt; String checked;

&gt; if (uiaddress)

&gt; checked="CHECKED";

&gt; else

&gt; checked="UNCHECKED";

&gt;

&gt; StringBuffer box=new StringBuffer();

&gt; box.append ("<input type=\"checkbox\"name=\""

&gt; +uiaddress+ "\" value=\"yes\" "+ checked + ">");

&gt; %>

> <%= box.toString()%>

>

>

> I have been using the following piece of code in the

> second jsp;

>

> String checked = request.getParameter("uiaddress");

>

> I can't seem to make it bring this value in.

>

> I then want to go ahead, update the database with the

> new value and display a read only checkbox on the page

> showing what it was set to in the previous jsp.

>

> Any help would be greatly appreciated.

>

JainA at 2007-6-29 11:45:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Create a hidden field. Write a javascript and call that function on 'onclick' event of the checkbox.

In the javascript, if anybody check's the checkbox set the value of that hidden field as 'Y'. Access the value of the hidden field in the next jsp page as any other parameter.

vasvoruganti at 2007-6-29 11:45:25 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...