Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript Validation in struts

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>

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

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

if(""==document.forms.contact.fname.value)
{
alert("Please enter your Father name.");
return false;
}

if(""==document.forms.contact.address.value)
{
alert("Please enter your address.");
return false;
}

if(""==document.forms.contact.dob.value)
{
alert("Please enter your Date of Birth .");
return false;
}
if(""==document.forms.contact.currentclass.value)
{
alert("Please enter Current class.");
return false;
}
if(""==document.forms.contact.name.value)
{
alert("Please enter Name.");
return false;
}
}
stop hiding script -->






</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/>
</table>
<html:submit/><html:cancel/>
</html:form>
</body>

</html>
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic