Solved

Dynamic JSP fields validation using Java Script?

Posted on 2006-07-11
4
2,289 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
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 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
communication with a non technical owner 16 101
library class in java 1 90
bean mapper frameworks 5 59
AlarmClock Challenge 35 145
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
An analysis of the phishing scam that has been affecting Google users, along with steps to take for protection, as well as what to do if you receive one of the emails.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now