This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Javascript and Struts Indexed properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Javascript and Struts Indexed properties" Watch "Javascript and Struts Indexed properties" New topic
Author

Javascript and Struts Indexed properties

Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Hello,
I have a HTML form that uses Struts indexed properties and hence looks kinda like this

When I use javascript to validate these fields the javascript fails because javascript cannot recognise "myprop[0]" as an element name. Any suggestions or work around?
Thanks


Commentary From the Sidelines of history
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4446
    
    5

Can you refactor so that you are calling JavaScript from an event in the form element itself? If you can, you can pass "this", e.g.
<html:text property="myprop[0]" onchange="javascript:foo(this);" />


Junilu - [How to Ask Questions] [How to Answer Questions]
Paul McKenna
Ugly Redneck
Ranch Hand

Joined: Jul 08, 2000
Posts: 1006
Thanks! I will try out that approach too. I found a way around though
Lets assume my html code looks like the following :

In the javascript function we can still validate these boxes by using the following script:

So basically the documents.myform.elements return an array with all the form elements. You have to remember that you will get everything within the form from labels to textboxes to button etc. So you have to use multiple if statements to check if the name of the element corresponds to something you want to validate and then perform the required validation.
HTH
SR
 
 
subject: Javascript and Struts Indexed properties
 
Similar Threads
How I can edit 'java.util.Set' DynaValidatorForm form-property
Submit form text fields (group) with same name
how to do submit the Dynamic produced element in Struts
Retrieving strings using getStrings() - DynaValidatorActionForm
DynaActionForms (struts 1.2) - form-property type