473,320 Members | 1,969 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,320 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 (preferably
without having to use 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 17 '05 #1
1 6001
Hello,

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 17 '05 #2

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...
4
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;"...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.