sunil_2215
03-27-2009, 06:54 PM
Hello friends...
I am a newbie to Javascript and JSP.
I wish to create a jsp file to read the inputs from an html (registration form called member.html), check validity of inputs using javascript and finally generate an ouput as an html file displaying the user inputs.
Following is the code for the member.html file
<HTML>
<TITLE>New member application form</TITLE>
<script language="JavaScript" src="javaScript.js" type="text/javascript"></script>
<!--<HEAD><H2><P align = "center">Welcome...</P></H2>-->
<H2><P align = "center"> Member Registration Form </p></H2>
</HEAD>
<HR>
<BODY>
<form method="post" action="ServerPage.jsp" name = "myform" >
<p><Strong>1. Tell us about yourself...</Strong></p>
First Name :<INPUT TYPE="text" NAME="firstName" SIZE="20" hspace="20"><br>
Last Name :<INPUT TYPE="text" NAME="lastName" SIZE="20"><br>
</p>
<p>
<Strong><em>Thanks for registering !</em></Strong><br>
<input onclick="test()" name="button" value="Submit" type="button">
<INPUT TYPE="reset" VALUE="Reset!"></H3></FONT>
</p>
</form>
</body>
</html>
Following is the code for the javascript.js file.
function test(){
var un = document.myform.firstName.value;
un = un.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces
un = un.replace(/[^a-z-]/gi,""); // strip characters apart from a-z apostrophe hyphen
if (un.length < 2) {
alert ("Enter valid first name...must be at least two characters");
document.myform.firstName.focus();
return;
}
var visn = document.myform.lastName.value;
visn = visn.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces
visn = visn.replace(/[^a-z-]/gi,""); // strip characters apart from a-z apostrophe hyphen
if (visn.length < 2) {
alert ("Last name must be at least two characters");
document.myform.lastName.focus();
return;
}
submit();
}
and following is the code for the ServerPage.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>response</title>
</head>
<body>
<% String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
%>
<h1>Hello <%= firstName %>! Welcome.</h1>
<h2>Your last name is <%= lastName %>.</h2>
</body>
</html>
The error i experience is that nothing happens when I click submit button...;)
I have installed Tomcat 6.0 and do not seem to have issues with that.
Folks, I do not wish to hijack an existing thread on this issue...but could not find an existing thread, hence a new thread.
Please advice.
Thanks in advance.
I am a newbie to Javascript and JSP.
I wish to create a jsp file to read the inputs from an html (registration form called member.html), check validity of inputs using javascript and finally generate an ouput as an html file displaying the user inputs.
Following is the code for the member.html file
<HTML>
<TITLE>New member application form</TITLE>
<script language="JavaScript" src="javaScript.js" type="text/javascript"></script>
<!--<HEAD><H2><P align = "center">Welcome...</P></H2>-->
<H2><P align = "center"> Member Registration Form </p></H2>
</HEAD>
<HR>
<BODY>
<form method="post" action="ServerPage.jsp" name = "myform" >
<p><Strong>1. Tell us about yourself...</Strong></p>
First Name :<INPUT TYPE="text" NAME="firstName" SIZE="20" hspace="20"><br>
Last Name :<INPUT TYPE="text" NAME="lastName" SIZE="20"><br>
</p>
<p>
<Strong><em>Thanks for registering !</em></Strong><br>
<input onclick="test()" name="button" value="Submit" type="button">
<INPUT TYPE="reset" VALUE="Reset!"></H3></FONT>
</p>
</form>
</body>
</html>
Following is the code for the javascript.js file.
function test(){
var un = document.myform.firstName.value;
un = un.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces
un = un.replace(/[^a-z-]/gi,""); // strip characters apart from a-z apostrophe hyphen
if (un.length < 2) {
alert ("Enter valid first name...must be at least two characters");
document.myform.firstName.focus();
return;
}
var visn = document.myform.lastName.value;
visn = visn.replace(/^\s+|\s+$/g,""); // strip leading and trailing spaces
visn = visn.replace(/[^a-z-]/gi,""); // strip characters apart from a-z apostrophe hyphen
if (visn.length < 2) {
alert ("Last name must be at least two characters");
document.myform.lastName.focus();
return;
}
submit();
}
and following is the code for the ServerPage.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>response</title>
</head>
<body>
<% String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
%>
<h1>Hello <%= firstName %>! Welcome.</h1>
<h2>Your last name is <%= lastName %>.</h2>
</body>
</html>
The error i experience is that nothing happens when I click submit button...;)
I have installed Tomcat 6.0 and do not seem to have issues with that.
Folks, I do not wish to hijack an existing thread on this issue...but could not find an existing thread, hence a new thread.
Please advice.
Thanks in advance.