• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with Form Validation

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a JSP page in which I am iterating four columns for 5 times. I need to validate one column for a particular date and one column for numbers. When I used JavaScript, its validating only the first one. How to validate all the rows. Here is the code sample.


<tr>
<td><b>Expense Date</b></td>
<td><b>Expense Type</b></td>
<td><b>Description</b></td>
<td><b>Amount in Rs</b></td>
</tr>
<% for(int i=0;i<5;i++)
{
%>
<TR>
<TD><html:text property="expdt" size="26"/></TD>
<TD><html:select property="expenseType" size="1">
<html ptions collection="exptype" property="shortName" labelProperty="name"/>
</html:select>
</TD>
<TD><html:text property="expdesc" size="27"/></TD>
<TD><html:text property="expamt" size="26"/></TD>
</TR>
<%
}
%>

Thanks in advance,
Regards,
Visu
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using the Struts Validation framework for this? If so, I'd recommend that you write your own JavaScript code instead, as the framwork doesn't handle validation very well in this type of situation.

If you are already using your own JavaScript, show us your code. I'd suggest using the Document Object Model (DOM) to iterate through the fields to validate them instead of trying to find them by name.
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the suggestion. I am using Javascript. I am trying to retrieve the values by name, which I am not able to perform correctly. Can you please give me a sample code of how to iterate through the fields using the Document Object Model, because I am just a novice is JavaScript.

Thanks in advance,
Visu
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to understand how to use the DOM in JavaScript, you are going to have to invest some time in learning it. Here are a couple of tutorials that may be useful.

http://www.howtocreate.co.uk/tutorials/javascript/dombasics

http://www.howtocreate.co.uk/tutorials/javascript/domtables

If, after reading these links, you still have questions, let us know.

Merrill
 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the links. Now I have another problem. I need to design a JSP page. The format is such that of a tab layout. When I click on a particular link, I need to have a group of checkboxes populated with values from database. Please help me out.

Thanks in advance,
Visu
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic