File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes JavaScript Validation in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JavaScript Validation in struts" Watch "JavaScript Validation in struts" New topic

JavaScript Validation in struts

pankaj semwal
Ranch Hand

Joined: Oct 07, 2008
Posts: 303
Hi List[],

I am doing java script validation in struts .I am not
using validator frame work.And i want to do validation using java script without using validator frame work of struts.But when i run the page on browse its not validationg the page.
Please help me.
My Code.

<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="" prefix="bean"%>
<%@ taglib uri="" prefix="html"%>

<title>JSP for StudRegForm form</title>
<script type="text/javascript">

<!-- hide script from older browsers
function validateForm(studRegForm)

alert("Please enter your Father name.");
return false;

alert("Please enter your address.");
return false;

alert("Please enter your Date of Birth .");
return false;
alert("Please enter Current class.");
return false;
alert("Please enter Name.");
return false;
stop hiding script -->


<html:form attribute="studRegForm" action="/studReg" onsubmit = "return validateForm(studRegForm);">

<table size=10 border=1>
FatherName : <html:text name="fname" property="fname"/> <br/>
Address : <html:text name="address" property="address"/> <br/>
Date Of Birth : <html:text name="dob" property="dob"/> <br/>
Current Class : <html:text name="currentclass" property="currentclass"/> <br/>
You Name : <html:text name="name" property="name"/> <br/>

David Newton

Joined: Sep 29, 2008
Posts: 12617

This isn't Struts-related, but JavaScript and DOM.

1) You need to use the DOM form element.
2) You need to use the form values from that form element, the JavaScript you show has something called "contact" in it that seems to appear out of nowhere.

I'd recommend searching the web for "javascript form validation".

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: JavaScript Validation in struts
It's not a secret anymore!