Solved

Dynamic JSP fields validation using Java Script?

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

13 Experts available now in Live!

Get 1:1 Help Now