Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Using form arrays within the javascript of a .jsp

Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


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 ]
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
    Bookmark Topic Watch Topic
  • New Topic