Re: javascript validations
On Monday, July 1, 2013 10:59:48 AM UTC+5:30, srilatha Palla wrote:
<%@ page import="da.ma.volks.Connector" %>
<%@page import="java.sql.*"%>
<%@ page import="java.awt.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1=
"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww=
w.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" src="mail.js"></script>
<script type="text/javascript">
function verify()
{
=09
var letters = /^[A-Za-z]+$/;
for( var i=0;i<document.getElementById("Registration").value.length;i++=
)
{
if (document.Registration.fname.value == ""
|| document.Registration.fname.value == null) {
alert(" firstname cannot be blank");
document.Registration.fname.focus();
=09
return false;
}
else
if (!document.Registration.fname.value.match(letters)) {
alert(" Enter alphabetics only in fname");
document.Registration.fname.focus();
return false;
}
else
if (document.Registration.lname.value == ""
|| document.Registration.lname.value == null) {
alert("LastName cannot be blank ");
document.Registration.lname.focus();
return verifyfname();
}
if (!document.Registration.lname.value.match(letters)) {
alert(" Enter alphabetics only");
document.Registration.lname.focus();
return false;
}
if (document.Registration.uid.value == "") {
alert("userid cannot be blank");
document.Registration.uid.focus();
return false;
}
var letter = "_";
if (document.Registration.uid.value.match(letter)) {
alert("underscores not allowed");
document.Registration.uid.focus();
return false;
}
if (document.Registration.pwd.value == "") {
alert("password cannot be blank");
document.Registration.pwd.focus();
return false;
}
if (document.Registration.pwd.value.length < 5) {
alert("Password must be more than 5 characters");
document.Registration.pwd.focus();
return false;
}
if (document.Registration.cfmpwd.value == "") {
alert("confirmpassword cannot be blank");
document.Registration.cfmpwd.focus();
return false;
}
if (document.Registration.cfmpwd.value.length < 5) {
alert(" confirmpassword should be more than 5 characters");
document.Registration.cfmpwd.focus();
return false;
}
if ((document.Registration.pwd.value) != (document.Registration.cfmpw=
d.value)) {
alert("Your password does not match");
document.Registration.cfmpwd.value == "";
document.Registration.cfmpwd.focus();
return false;
}
if (document.Registration.country.value == "") {
alert(" country cannot be blank");
document.Registration.country.focus();
return false;
}
if (document.Registration.mobile.value == "") {
alert("Mobilenumber cannot be blank");
document.Registration.mobile.focus();
return false;
}
var d = new Date();
var date = d.getDate();
var month = d.getMonth() + 1;
var year = d.getFullYear();
var cdate = document.Registration.birthday.value;
var cmonth = document.Registration.birthday_month.value;
var cyear = document.Registration.birthday_year.value;
if (document.Registration.birthday_month.value == "") {
alert("Mobilenumber cannot be blank");
document.Registration.birthday_month.focus();
return false;
}
if (cmonth > month && cyear > year) {
alert("Month is not valid month");
document.Registration.birthday_month.focus();
return false;
}
if (cyear > year) {
alert("Year is not valid year");
document.Registration.birthday_year.focus();
return false;
}
if (cdate > date && cmonth > month && cyear > year) {
alert(" Date is not valid date");
document.Registration.birthday.focus();
return false;
}
}
return true;
}
function getCountryCode() {
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, S=
afari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//alert(CountryCode);
document.getElementById("CountryCode").value = xmlhttp.responseText=
;
}
}
var country = document.getElementById("country").value;
xmlhttp.open("GET", "getCountryCode.jsp?country=" + country, true);
xmlhttp.send();
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-885=
9-1">
<title>Registration Page</title>
</head>
<body bgcolor="#33CCFF" onload="document.Registration.fname.focus()">
<center>
<font face="Times New Roman,Times" size="+3">
Registration Page</font>
</center>
<div align="center">
<form name="Registration" action="Process.jsp" method="POST"=
>
<input type="hidden" name="expid" value="%% EXPID %=
%" >
<div></div>
<center><table cellspacing="2" cellpadding="4" border=
="0" >
<tbody >
<tr>
<td class="normalfont"><font face="calibri" siz=
e="+1">FirstName</font> </td>
<td>
<input type="text" class="formInput" name="=
fname" onblur="return verify(this.value,1,0)" /></td>
</tr>
<tr>
<td class="normalfont"><font face="calibri" siz=
e="+1">LastName:</font></td>
<td>
<input type="text" class="formInput" name="=
lname" onblur="return verify(this.value,1,0)" /></td>
</tr>
<tr>
<td ><font face="calibri" size="+1">Preferred U=
serId</font></td>
<td>
<input type="text" class="formInput" name="=
uid" /></td>
</tr>
<tr>
<td ><font face="calibri" size="+1">Password</f=
ont></td>
<td>
<input type="password" class="formInput" name=
="pwd" /></td>
</tr>
<tr>
<td class="normalfont"><font face="calibri" siz=
e="+1">Confirm Password</font></td>
<td>
<input type="password" class="formInput" name=
="cfmpwd" /></td>
</tr>
<tr>
<td class="normalfont"><font face="calibri" siz=
e="+1">Country</font></td>
<td>
<select name="country" id="country" onchange==
"getCountryCode()" >
<option>- - Select Country - - </option>
<%
Connection conn =Connector.getCon();
PreparedStatement psmt = conn.prepareStatement(=
"select COUNTRY from ISDCODE where status='Active'");
ResultSet rs = psmt.executeQuery();
while(rs.next())
{
String country = rs.getString(1);
%>
<option value="<%=country%>"><%=country %>=
</option>
<%}
=09
%>
</select>
</tr>
<tr>
<td class="normalfont"><font face="calibri" siz=
e="+1">Email</font></td>
<td>
<input type="text" class="formInput" name="=
email" onblur="return (ValidateForm());" /></td>
</tr>
<tr>
Here is my code.i m getting alert messages continously without inserting da=
ta in the field .this is bcz i kept blur on each field and calling validati=
on error method....can anyone suggest any other alternative...i need the fi=
eld by field validation i.e.,if firstname left empty i should generate an e=
rror at runtime on beside of that textbox.....like google+ reg page...can a=
nyone pls send the code for two fields n how to cal error message.........=
..............
I m new to java .please anyone resolve my issue...