File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using form arrays within the javascript of a .jsp

 
Karl Beowulph
Ranch Hand
Posts: 130
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having difficulty assigning an array (called rows) from my jsp page to a var within the jsp.

I'm been trying things like:

var myArray = document.forms[0].rows

and

var myArray = document.forms[0].elements.rows

but the results are always invalid. I know that the name is correct, because when I cycle through the elements on the form the names of the elements within the array (rows[0].name etc) show up.

This is the value I want to transfer.


I'd like it in a javascript array so that I can do some checks on it before I submit the form. I can't use java (so far as I know) to retrive the values because I need to test it on data that the user enters into the form.
[ August 18, 2004: Message edited by: Karl Beowulph ]
 
Jason Menard
Sheriff
Posts: 6450
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is some confusion about how to access form elements in JavaScript, or possibly confusion over how JSP variables may be accessed by JavaScript.

In any event, <nested:iterate> will produce the following code:



Given the above, the JavaScript has no access to anything called "rows". Let's assume for a minute that those are the only form elements on your page. In that case, one way that JavaScript can access the values of the three text fields like this:

var val1 = document.forms[0].elements[0].value

In the above case, the value of the variable val1 would be whatever was typed into the text field named data1.

I hope this points you in the right direction. I'm going to go ahead and move this to the HTML and JavaScript forum where you can get better answers to JavaScript questions.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic