• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript string array to server

 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic