Solved

Dynamic JSP fields validation using Java Script?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hashcode is calculated on the basis of value object 2 131
authenticate preemptively soap ui option 3 178
struts exact match support 3 63
mask rule in struts validation.xml 5 104
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

739 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