• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unchanged dynamically created check boxes not in request object.

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating a dynamic number of checkboxes, all with the same name but different text in the values attribute of the checkbox tag. The problem is I am getting the value for the first(index 0) check box using the

and the value for any checkbox that was changed by the user. But I am not getting the value, (I am getting a blank) for check boxes that were not changed. Giving each checkbox a unique name does not solve the problem either. Any ideas on how to get the values, of the unchanged checkboxes, into the request object?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
firstly, i didn't get why you need the values of unchecked check boxes. but if you want to get them, then you can run a javascript before the form submits, by transfering them into some hidden form fields. then you can access them on the other page.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is well-known browser behavior. It's not just check boxes either, the same thing happens with text fields etc.
When browser forms were first introduced it was seen as a sensible network efficiency move to nt send back values which have not changed. After all, surely whoever wrote the page knows the default values, so no reply is the same as a default reply.
There are several ways round this.
The most robust is to "go with the flow" and accept that unchanged fields will not be returned, and take a note of the initial values (in the session, for example) when you generate the page. Then if you don't get anything back from the browser for a field you just look up the default value from the session.
Other ways include adding a little JavaScript to the page which "tweaks" the values to ensure they all get returned to the server. This is pretty simple with text fields, you just need to add a known prefix to the values, and strip it off in the form handler. It's harder for checkboxes, so it's not really recommended.
How are you generating these "dynamic" checkboxes ?
 
Paul Roubekas
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using custom tags to create the dynamic check boxes. Why then do I get the unchanged values for a SELECT and TEXTAREA that I create at the same time in the same way?

[ July 29, 2002: Message edited by: Paul Roubekas ]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CheckBox and option button values are not sent to the back end at all if they are not checked. Textboxes send a null for the value if nothing is entered.
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic