• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

checkboxes persistence

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i have a bunch of checkboxes in a form and i use a JSP to render them.
There is a provision to save the form so that it can be filled out later.
The problem is:

when i check some checkboxes and save the form and later on when i open the form using a link, the same JSP renders it but now the checkboxes are all unmarked.

i tried to set their values as 'off' (when unchecked) when submitting and also wrote an onclick event to update the value accordingly. it doesnt seem to work even after that.

and the solution for creating a hidden field with the same name as the checkbox will not work for me as it is causing me some logic failure while validating the form.

i am using struts 1.2 or more and i dont have access to formbean code and i need to resolve this without touching the source code.

I am trying to add a postfix such as "ON" to the end of a checkbox property

<blockquote>code:
<pre name="code" class="core"><html:checkbox name="<%=somename%>" property="<%=someProperty%>" /></pre>
</blockquote>

i am using an onclick event to check the checked state of a checkbox and appropriately update a global js variable with the value and while submitting i want to append this global js variable to the <blockquote>code:
<pre name="code" class="core"><%= someProperty%></pre>
</blockquote> variable. Later on when rendering the form, i would just check the presence of the global variable in the property and make the box as checked.

But the problem is that i don't seem to have any ideas as to how to accomplish this using JavaScript as the checkbox rendering goes on in a loop in the jsp and i need to add this postfix while submitting and i wont have a reference to this property at the end when the form would have been fully rendered.

any ideas?

thanks in advance for reading such a long post. appreciate that.
 
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To cause a checkbox to be checked, you need to include the checked attribute: checked="checked".

It doesn't matter what the value is set to; the mere presence of the attribute enables the checked state.
 
Mohd Asim
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am setting the "checked" property of the checked checkboxes through a script at the time of submitting the form. Still i am unable to view them as checked when the form is redisplayed after saving. i just want to view the boxes that were checked, not worried about the unchecked ones.
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the attribute on the page before they are displayed won't automatically do anything for making them checked on the current page. You must set the checked attribute for all checkboxes that you want checked on the current page.

If you are using JSP this is easy to do. Just look at which checkboxes were checked on the way in, and make sure that those checkboxes have the checked attribute when you generate them for the current page.
 
Mohd Asim
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all. I got the solution.

At the time of submitting the form I wrote a script to check the checked status of a checkbox and accordingly set the checkbox values as "true" or "false". That worked.

Thanks again
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Edit: redundant question removed]
[ July 24, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Marshal
Posts: 67300
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prabhu rangan, please do not cross-post the same question more than once. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!