• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing checkbox array

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have following code in my jsp
...this code inside <logic:iterate tag> so it generates many checkboxes
<input type="checkbox" name="addAddresses[]" id="addAddresses[]" class="checkboxgroup1" value="<bean:write name="results" property="locationAddress" />"/>
....<logic:iterate> ends here

now i want to pass this checkbox group (the selected values) to thye servlet using my javascript function which looks like this

opener.location.href = "addressFind.do?requestAction=addAddresses&oid=" + oid

i tried passing it as a parameter but i m not able to .
how can i pass the selected checkboxes.
Thanks
Imad
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are not submitting a form, you need to loop through the elements and build a string containing the information.

Eric
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the exact syntax of doing that because I am trying to do something like this

document.getElementById ( "addAddresses" )[i].checked (where i is a loop variable

and of course it dont work.
thanks for your help
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you making it hard on yourself and using opener.location.href instead of submitting a form?
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried the following which apparently should work but its not working

var check = document.getElementById ("addAddresses") ;
alert (check.length);
for ( i = 0 ; i < check.length ; i ++ ){
alert ( check.checked ) ;
}

it says check.length is undefined and when i use check.size it gives the value of 0 although there are ten checkboxes. also when i try check.checked it gives me true or false depending on the first checkbox if its checked or not.

Thanks
Imad
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IDs are singular so you can only have one element with the id. LIke an id number. Names are plural.

Eric
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear and Eric

I would probably submit the form. The reason I was not submitting the form was because I need to close popup when this function is performed and also refresh the opener. Anyways I think I can submit the form and still be able to refresh my parent window. Thanks for your help.

By the way I found what I was doing wrong when i tried to access my checkboxes. I was supposed to call document.getElementsByName("addAddresses")
rather than ...ById.

Imad
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you not doing a form submission? You are recreating a normal form. LOL

Eric
reply
    Bookmark Topic Watch Topic
  • New Topic