my dog learned polymorphism*
The moose likes Struts and the fly likes Problem with Form Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with Form Validation" Watch "Problem with Form Validation" New topic
Author

Problem with Form Validation

visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
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
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Sep 06, 2005
Posts: 122
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Form Validation