The moose likes HTML, CSS and JavaScript and the fly likes Using form arrays within the javascript of a .jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Using form arrays within the javascript of a .jsp" Watch "Using form arrays within the javascript of a .jsp" New topic

Using form arrays within the javascript of a .jsp

Karl Beowulph
Ranch Hand

Joined: May 31, 2004
Posts: 130
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


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

Joined: Nov 09, 2000
Posts: 6450
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.
I agree. Here's the link:
subject: Using form arrays within the javascript of a .jsp
It's not a secret anymore!