Re: javascript validations

Discussion in 'Java' started by srilatha Palla, Jul 1, 2013.

  1. 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://www.w3.org/TR/html4/loose.dtd">
    >
    > <html>
    >
    > <head>
    >
    >
    >
    > <script language="javascript" src="mail.js"></script>
    >
    >
    >
    > <script type="text/javascript">
    >
    >
    >
    > function verify()
    >
    > {
    >
    >
    >
    >
    >
    > 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();
    >
    >
    >
    > 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.cfmpwd.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, Safari
    >
    > 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-8859-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" size="+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" size="+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 UserId</font></td>
    >
    > <td>
    >
    > <input type="text" class="formInput" name="uid" /></td>
    >
    > </tr>
    >
    > <tr>
    >
    > <td ><font face="calibri" size="+1">Password</font></td>
    >
    > <td>
    >
    > <input type="password" class="formInput" name="pwd" /></td>
    >
    > </tr>
    >
    > <tr>
    >
    > <td class="normalfont"><font face="calibri" size="+1">Confirm Password</font></td>
    >
    > <td>
    >
    > <input type="password" class="formInput" name="cfmpwd" /></td>
    >
    > </tr>
    >
    >
    >
    > <tr>
    >
    > <td class="normalfont"><font face="calibri" size="+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>
    >
    >
    >
    > <%}
    >
    >
    >
    > %>
    >
    > </select>
    >
    > </tr>
    >
    > <tr>
    >
    > <td class="normalfont"><font face="calibri" size="+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 data in the field .this is bcz i kept blur on each field and calling validation error method....can anyone suggest any other alternative...i need the field by field validation i.e.,if firstname left empty i should generate an error at runtime on beside of that textbox.....like google+ reg page...can anyone pls send the code for two fields n how to cal error message.......................
    I m new to java .please anyone resolve my issue...
    srilatha Palla, Jul 1, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Paugh

    vbscript validations and .NET

    Jon Paugh, Dec 17, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    439
    bruce barker
    Dec 17, 2003
  2. Gary Smith

    Validations......

    Gary Smith, Feb 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    567
  3. DotNetJunkies User
    Replies:
    1
    Views:
    358
    Teemu Keiski
    May 1, 2004
  4. Murat YILMAZ

    Page client validations are not working...

    Murat YILMAZ, Oct 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,821
    Scott Allen
    Oct 31, 2004
  5. Joerg Meier

    Re: javascript validations

    Joerg Meier, Jul 1, 2013, in forum: Java
    Replies:
    0
    Views:
    218
    Joerg Meier
    Jul 1, 2013
Loading...

Share This Page