?
Solved

Dynamic JSP fields validation using Java Script?

Posted on 2006-07-11
4
Medium Priority
?
2,306 Views
Last Modified: 2008-03-04
I am generating a JSP page with Dynamic fields in it.I am using the following code in JSP page


<c:forEach items="testitem" var="index">
  <html:text property='myProperty(${index})'/>
</c:forEach>

ActionForm Code to access the above property:

public class testForm extends ActionForm
{
  private HashMap hMap = new HashMap();

    public void setMyProperty(String key, Object value)  {
    this.hMap.put(key, value);
  }

  public Object getMyProperty(String key)   {
    return this.hMap.get(key);
  }

  }

I am trying to write the validation code in javascript but when i am trying to refer the dynamic fields by name

    document.myForm.myProperty("index1").value;

i am getting the error object does not support this property.I do not know how to access the dynamic fields in java script.
Can anybody please help me?

Thanks a lot
Anshu



0
Comment
Question by:ANSHU2004
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 17088144
document.myForm.myProperty("index1").value;
should be
document.myForm.index1.value;

0
 
LVL 11

Expert Comment

by:Manish
ID: 17088712
After generating output check HTML in view souce .SO that you will correct name for text field.
  Also you can calculate count no which u can access in javascript so that u get to know how many text fields get generated. And u can validate these fields.

Karan
0
 
LVL 4

Expert Comment

by:Meritor
ID: 17088718
If the index is unique you can get this by
document.getElementById("index1").value;
but the HTML tag you are writing must contain id="index1"
e.g. <Input type="text" id="index1" />
0
 
LVL 12

Accepted Solution

by:
jessegivy earned 1000 total points
ID: 17094208
I'm gonna assume that you're attempting to do dynamic validation without knowing what the id's of the form elements are?  What is "index1"?  Is it an id of an elment in your form?  There are a few suggestions I can make.  First of all it's important to note that not all elements have a value property.  If you really NEED to perform validation in this way you'll need to define clear validation rules for each of the element types you want to validate.  If this is what you want to do, then you'll need to get each element by type:

document.getElementsByTagName("input")

..will return all the <input> tags

document.getElementsByType("checkbox")

...will return an array of all the checkbox elements

document.getElementsByTagName("select")

...will return an array of all the select boxes in the document.

Hope this helps, but you may find it easier to just do validation in each page statically?

~Jesse
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With the evolution of technology, we have finally reached a point where it is possible to have home automation features like having your thermostat turn up and door lock itself when you leave, as well as a complete home security system. This is a st…
Geo-targeting is the practice of distributing content based on a person’s location, as best as you can determine it. Let’s look at some ways you could successfully use this tactic. The following tips and case studies could lead to meaningful results.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question