473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Checkbox problem - checkboxes submitting that are unchecked

Hello,

I am having a problem in my struts application with the checkboxes in
my form. I have an array of checkboxes, some of which may be already
selected when the form loads. My problem is when the user then
deselects one or more of these checkboxes and submits the form -
they're being submitted as if they were still checked, when the user
has infact deselected them.

I've heard that this is a common problem, but I don't seem to be able
to find the problem / resolution with any search criteria. If anybody
knows the fix for this it would be greatly appreciated (if there is a
solution without using Javascript I would prefer this as we're trying
to write the application so it's not too dependant on Javascript . . .)

Many Thanks, Claire

Here's the HTML for the checkbox part of the form when it's initially
loaded.

<table style="width:50%;" cellpadding="0" cellspacing="0">
<tr class="spreadsheetvalue">
<td align="left" width="85%">Red</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[0].add" value="on"
checked="checked">
</td>
</tr>
<tr class="spreadsheetvalue">
<td align="left" width="85%">Orange</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[1].add" value="on"
checked="checked">
</td>
</tr>
<tr class="spreadsheetvalue">
<td align="left" width="85%">Yellow</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[2].add" value="on"
checked="checked">
</td>
</tr>
<tr class="spreadsheetvalue">
<td align="left" width="85%">Green</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[3].add" value="on">
</td>
</tr>
<tr class="spreadsheetvalue">
<td align="left" width="85%">Blue</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[4].add" value="on">
</td>
</tr>
<tr class="spreadsheetvalue">
<td align="left" width="85%">Purpler</td>
<td align="left" width="15%">
<input type="checkbox" name="cust[5].add" value="on">
</td>
</tr>
</table>

Jul 23 '05 #1
4 10752
Claire wrote:
Hello,

I am having a problem in my struts application with the checkboxes in
my form. I have an array of checkboxes, some of which may be already
selected when the form loads. My problem is when the user then
deselects one or more of these checkboxes and submits the form -
they're being submitted as if they were still checked, when the user
has infact deselected them.


Works as expected in Safari 1.0.3, IE 5.2 and Firefox 1.0 on Mac
OS X - only checked inputs are submitted.

So this is pure conjecture ... you may want to try using plain
checked instead of checked="checked" if your doctype is
HTML 4.01.

You may want to change the value to "yes" (or anything other
than "on"), as perhaps some browsers are being confused by your
setting the initial value to "on".

[...]

A slimmer version:

<form action="">
cust0<input type="checkbox" name="cust[0].add" value="on"
checked ><br>
cust1<input type="checkbox" name="cust[1].add" value="on"
checked ><br>
cust2<input type="checkbox" name="cust[2].add" value="on"
checked ><br>
cust3<input type="checkbox" name="cust[3].add" value="on"><br>
cust4<input type="checkbox" name="cust[4].add" value="on"><br>
cust5<input type="checkbox" name="cust[5].add" value="on"><br>
<input type="submit">&nbsp;<input type="reset">
</form>

--
Fred
Jul 23 '05 #2
Hello,

I don't think I can actually control what is output there as I am using
Struts and JSTL which produces the HTML for me, this is the actual
Struts / JSTL code:

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/c" prefix="c" %>

<table style="width:50%;" cellpadding="0" cellspacing="0">

<c:forEach
var="customers"
items="${sessionScope.rescheduleForm.map.customers }"
varStatus="status">

<tr class="spreadsheetvalue">
<td align="left" width="85%">

<html:text
name="customers"
property="customerName"
readonly="true"
size="25" />

</td>
<td align="left" width="15%">

<html:checkbox
name="customers"
property="reschedule"
indexed="true" />

</td>
</tr>
</c:forEach>
</table>

The HTML I sent in the initial example I changed names to make it
easier to read, but I have not coded to produce HTML that says
checked="checked" or value="on"
the JSTL / Struts produces that.

Many Thanks, Claire

Jul 23 '05 #3
Claire wrote:
I am having a problem in my struts application with the checkboxes in
my form.


I suspect that your problem isn't checkboxes.
In struts, you need to reset your form object and make sure that your
checkbox values are set to false before populating the form from the
browser's input. Otherwise, you'll see them as true.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #4
Hello,

Thanks for pointing me in the right direction. My problem was that I
had not implemented a

reset (ActionMapping mapping, HttpServletRequest request)

method. So for those who know Struts, I had to change my DynaActionForm
and create a normal Action Form which implemented a reset() method. The
reset method looped through the array, setting the boolean
(representing the checkbox) to false.

The reset() method is automatically called before my preload action to
prepolulate values (so only reset if the array isn't null, otherwise I
got a NullPointerException) and then again once the form is submitted
(the crucial bit, initialising checkboxes back to false and then
populating with the selected form values).

Many Thanks, Claire

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Pete | last post by:
I have some session variables which get set on page one of my site. I can set an unset these by passing through a parameter in some URL's. When the user goes to the second page some checkboxes are...
1
by: Claire | last post by:
Hello, I am having a problem in my struts application with the checkboxes in my form. I have an array of checkboxes, some of which may be already selected when the form loads. My problem is when...
4
by: RodBillett | last post by:
I have a situation where I have 3 checkboxes - and at least 1 needs to be selected at all times... I have implemented the code that allows this behavior to happen, BUT Viewstate gets all messed...
4
by: david | last post by:
I have an array of CheckBoxes which dynamically display in a web form. How to detect and determine which CheckBox' check status changed? For example, Array(i, j) from checked to Unchecked and...
16
by: GTi | last post by:
I want to use a 'smarter' checkbox using span. When a user press the text the checkbox is checked. But this dos't work as expected. Any idea? <span style="cursor:pointer;"...
3
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
0
by: rn5a | last post by:
I have a DataGrid where in the first column of each row is a CheckBox (the CheckBoxes reside in the TemplateColumn of the DataGrid). The CheckBox's AutoPostBack property is set to True & its...
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
0
by: J | last post by:
I'm dynamically adding checkboxes in the Page_Load (regardless of PostBack). When IsPostBack, the checkboxes display as I expected and their checked/unchecked status is also as expected. At this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.