[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Dynamic JSP fields validation using Java Script?

Posted on 2006-07-11
4
Medium Priority
?
2,308 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

834 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