File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to show whick checkbox is checked in jsp page without submit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to show whick checkbox is checked in jsp page without submit?" Watch "how to show whick checkbox is checked in jsp page without submit?" New topic
Author

how to show whick checkbox is checked in jsp page without submit?

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
let said,

group1: checkbox1, checkbox2, checkbox3
group2: checkbox4, checkbox5, checkbox6
group3: checkbox7, checkbox8, checkbox9

if user check the checkbox 1, then the page will show a table with content
col1 col2
row1 group1 checkbox1.value

if user check the checbox 5, 6, the the page will show a table with content
col1 col2
row1 group1 checkbox1.value
row2 group2 checkbox5.value, checkbox6.value

that is, the table will show the checkbox user checked, without submit the form, is it possible to do this using javascript? if possible, how to write it??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

First, it sounds more like you want a radio button, not a checkbox--but if you want to be able to show all of them, that's fine too. (You could certainly do it with checkboxes as well, there would just be more JavaScript.)

Second, use a library like jQuery, Prototype, etc. and attach a click handler to your checkboxes. If the data is already on the page, just hide/show the appropriate div. If you need to retrieve the data, make an Ajax call and set the contents of a div with the result.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
David Newton wrote:First, it sounds more like you want a radio button, not a checkbox--but if you want to be able to show all of them, that's fine too. (You could certainly do it with checkboxes as well, there would just be more JavaScript.)

Second, use a library like jQuery, Prototype, etc. and attach a click handler to your checkboxes. If the data is already on the page, just hide/show the appropriate div. If you need to retrieve the data, make an Ajax call and set the contents of a div with the result.


why need to use library like jQuery etc? is it very difficult to implement this function using pure javascript? I am not the project leader and I afraid my supervisor not allow me to use extra library....
I need to use checkbox because the application allow user to select more than one item in a group.
About ajax, if each click cause a partial submit, will this make the application very slow response? I haven't use ajax before.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because it makes writing JavaScript easier. Of course it's not *necessary*--it's written in JavaScript, so anything you do with jQuery, you can do in "raw" JavaScript.

As far as making it "slow" goes, it depends on when you want it to be slow: on the initial page load, where it loads all the data, or on the checkbox click. It doesn't really matter very much (probably--hard to say without knowing more).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to show whick checkbox is checked in jsp page without submit?
 
Similar Threads
CRUD approach
comparing two checkbox groups
checkboxes from a query , How to ?????
Passing Table values to action class
JCheckBox in JTable Rendering problem