This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 8877
    
    8

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: 8877
    
    8

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Fetching checked data from html:checkbox inside logic:iterate