• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetching checked data from html:checkbox inside logic:iterate  RSS feed

 
Sachin Ag
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an onsubmit or onclick handler?

Moving to HTML/JavaScript.
 
Sachin Ag
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Sachin Ag
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!