| Author |
Javascript string array to server
|
basha khan
Ranch Hand
Joined: Jan 26, 2002
Posts: 516
|
|
Anybody know how to send a javascript string array(or values) to server in struts?. In Detail [ January 18, 2006: Message edited by: basha khan ]
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
First of all, the tag: <html:hidden property = "stringsSelected"/> Will not work if stringsSelected is an array. If you use the view Source function of your browser, you will see that the rendered code is not what you expect. You would need to write something like this: <c:forEach var="element" items="${myForm.stringsSelected}" varStatus="status"> <input type="hidden" name="stringsSelected" value="${myForm.stringsSelected[status.index]}" > </c:forEach> This will generate one hidden tag for each element of the array. If you wish to replace this array with a javaScript array, you will have to create a loop and replace them one element at a time. Something like this: var elements = document.getElementsByName("stringsSelected"); for (var i=0;i<elements.length;i++) { elements[i].value = myJavaScriptArray[i]; } This assumes the arrays are of the same length.
|
Merrill
Consultant, Sima Solutions
|
 |
 |
|
|
subject: Javascript string array to server
|
|
|