| Author |
passing checkbox array
|
Muhammad Imad Qureshi
Ranch Hand
Joined: Sep 13, 2005
Posts: 238
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Sep 13, 2005
Posts: 238
|
|
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
Joined: Jan 10, 2002
Posts: 56191
|
|
|
Why are you making it hard on yourself and using opener.location.href instead of submitting a form?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Muhammad Imad Qureshi
Ranch Hand
Joined: Sep 13, 2005
Posts: 238
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Sep 13, 2005
Posts: 238
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
Why are you not doing a form submission? You are recreating a normal form. LOL Eric
|
 |
 |
|
|
subject: passing checkbox array
|
|
|