Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unchanged dynamically created check boxes not in request object.

 
Paul Roubekas
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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?
 
sreenivas chalam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic