Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes Fetching checked data from html:checkbox inside logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Fetching checked data from html:checkbox inside logic:iterate" Watch "Fetching checked data from html:checkbox inside logic:iterate" New topic
Author

Fetching checked data from html:checkbox inside logic:iterate

Sachin Ag
Greenhorn

Joined: Sep 15, 2010
Posts: 5
Hello

I have a list of checkbox generated dynamically using logic:iterate. Here's the code :


What i want is that in the javascript to obtain the checkbox selected after i hit submit.

The view source part of that page looks like this..



Please let me know how to proceed.

Thanks
Sachin
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use an onsubmit or onclick handler?

Moving to HTML/JavaScript.
Sachin Ag
Greenhorn

Joined: Sep 15, 2010
Posts: 5
But the question here is how do i call the checked property in javascript.
Like something we have document.forms[0]. something something..
How do i get the value. There will be multiple checkboxes and i want to know the checkboxes selected.
Will be grateful if you provide some code snippet based on my example.

Regards
Sachin
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Same way as with any other DOM form element (although the brackets in the name will require not using the normal dot-notation, I think?)
Sachin Ag
Greenhorn

Joined: Sep 15, 2010
Posts: 5
Sir i have tried all possible way. Probably we need to iterate through something and then check individually if the checkbox was selected.
I tried to fetch something like this : document.forms[0].details[0].checked -- > this gave me error
document.forms[0].details -- > this gave me undefined
document.forms[0].availablePaymentDetailsList --> undefined
document.forms[0].availablePaymentDetailsList.length --> error

So please let me know with an working example.

Regards
Sachin
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Sachin Ag wrote:
I tried to fetch something like this : document.forms[0].details[0].checked -- > this gave me error
document.forms[0].details -- > this gave me undefined


As it should. Your checkbox's name is "details[0].checked". Your examples try to dereference document.forms[0].details and there's nothing there. Try something like:



"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Sachin Ag
Greenhorn

Joined: Sep 15, 2010
Posts: 5
I tried something like this:


It gave me an alert of [object] and not the value though it's value was true. Can you please suggest me some other alternative.
Also how will I come to know the length of the arraylist in javascript.

Regards
Sachin
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Sachin Ag wrote:It gave me an alert of [object] and not the value though it's value was true.


The object you printed out is the checkbox itself. See here for the properties of that object.
 
wood burning stoves
 
subject: Fetching checked data from html:checkbox inside logic:iterate
 
Similar Threads
How to get results from indexed fields????
Selecting a single row in a table, then saving that index in the struts form
how to use- html:checkbox - and iterate it through - logic:iterate
How to submit value and reflect value in check box
Attempting to get a parameter from a link