• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing checkbox array

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • 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
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you not doing a form submission? You are recreating a normal form. LOL

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic