Jsp code is not working after some modification in design why?

hi,
I am in the final touch of my course work in jsp.i did all the coding and tested..everything was working properly..after i did some modification in the structure of the page the update query is not working..i dont understand why?
i am attaching my old page and new page here...plz help me to solve this...
old page editstudent.jsp
<html>
<body>
<%@ page language="java" import="java.sql.*,java.text.SimpleDateFormat,java.util.Date" %>
<%
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("dd-MM-yyyy");
String refno=request.getParameter("refno");
     String student=request.getParameter("student");
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection con=DriverManager.getConnection("jdbc:odbc:lsmsdsn","","");
     Statement st1=con.createStatement();
ResultSet rs=st1.executeQuery("select * from sponsordetails where refno='"+refno+"'");
%>
<form name=editsponsorform method="POST" action="editsponsor.jsp" >
<input type="text" name="refno" size="20" value="<%=refno%>"></p>
<p>Sponsor Name <input type ="text" name="sponsorname" size="50" value="<%=rs.getString(2)%>"></p>
<p>Sponsor's Address&nbsp<textarea name="sponsorsaddress" rows="5" cols "80" tabindex="10"><%=rs.getString(3)%></textarea></p>
<p>Sponsor's Phoneno <input type ="text" name="sponsorsphoneno" size="30" value="<%=rs.getInt(4)%>"></p>
<p>Sponsor's Fax <input type ="text" name="sponsorsfax" size="30" value="<%=rs.getInt(5)%>"></p>
<input type="submit" name="b1" value="Save & Continue" >
<input type="Reset" name="b2" value="Cancel "onClick="window.location='home.html'">
old page editsponsor.jsp
<html>
<body>
<%@ page language="java" import="java.sql.*,java.text.SimpleDateFormat,java.util.*" %>
<%
String refno=request.getParameter("refno");
String sponsorname=request.getParameter("sponsorname");
String sponsorsaddress=request.getParameter("sponsorsaddress");
String d=request.getParameter("sponsorsphoneno");
int sponsorsphoneno=Integer.parseInt(d);
String d1=request.getParameter("sponsorsfax");
int sponsorsfax=Integer.parseInt(d1);
Connection con =null;
try
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:lsmsdsn","","");
     PreparedStatement st=con.prepareStatement("update sponsordetails set sponsorname= ?,sponsorsaddress=?,sponsorsphoneno=?,sponsorsfax=? where refno=?");
st.setString(1,sponsorname);
out.println(sponsorname);
st.setString(2,sponsorsaddress);
st.setInt(3,sponsorsphoneno);
st.setInt(4,sponsorsfax);
st.setString(5,refno);
st.executeUpdate();     
     st.executeUpdate();
     out.println("record updated successfully"+"<A HREF='loginhtml.html'>login page</A>.");
finally {
     try {
          if (con !=null) {
          con.close();
     catch (SQLException se)
     out.println(se.getMessage());
%>
</body>
</html>
New page editstudent.jsp
<html>
<body>
<%@ page language="java" import="java.sql.*,java.text.SimpleDateFormat,java.util.Date" %>
<%
SimpleDateFormat formatter;
formatter = new SimpleDateFormat("dd-MM-yyyy");
String refno=request.getParameter("refno");
     String student=request.getParameter("student");
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     Connection con=DriverManager.getConnection("jdbc:odbc:lsmsdsn","","");
     Statement st1=con.createStatement();
ResultSet rs=st1.executeQuery("select * from sponsordetails where refno='"+refno+"'");
%>
<form name=editsponsorform method="POST" action="editsponsor.jsp" onSubmit="return validateEditsponsorform()">
<table width="821" border="1" align="center" bordercolor="#F8F8F8" bgcolor="#F5F5F5">
<tr>
<td colspan="6" bgcolor="#CCCCCC"><p class="style6"> </p>
<p class="style6"> </p>
<p class="style6"> </p></td>
</tr>
<tr>
<td width="130">Ref No:</td>
<td width="158">
<input type="text" name="refno" disabled="true" value="<%=refno%>" />
</td></tr>
<tr>
<td width="130">Sponsor Name</td>
<td width="158">
<input type="text" name="sponsorname" value="<%=rs.getString(2)%>"/>
</td></tr>
<tr>
<td>Sponsor's Address:</td>
<td>
<textarea name="sponsorsaddress" cols="20" rows="5"><%=rs.getString(3)%></textarea>
</td></tr>
<tr>
<td>Sponsor's Phone No:</td>
<td>
<input type="text" name="sponsorsphoneno" value="<%=rs.getInt(4)%>"/>
</td></tr>
<tr>
<td>Sponsor's Fax:</td>
<td>
<input type="text" name="sponsorsfax" value="<%=rs.getInt(5)%>" />
</td></tr>
<tr>
<td>
<input type="submit" name="b1" value="Submit & continue" />
</td>
<td><label>
<input type="reset" name="b2 " value="cancel" onClick="window.location='home.html'" />
</td>
</tr>
</table>
</form>
new page editsponsor.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit</title>
<style type="text/css">
<!--
.style2 {
     color: #CC6600;
     font-weight: bold;
     font-size: small;
.style4 {
     color: #0000CC;
     font-weight: bold;
     font-size: large;
-->
</style>
</head>
<body bgcolor="#F5F7F4" topmargin="0">
<%@ page language="java" import="java.sql.*,java.text.SimpleDateFormat,java.util.*" %>
<div align="center">
<table width="800" border="0" cellpadding="0" cellspacing="0" bgcolor="#FBFCFF">
<!--DWLayoutTable-->
<tr>
<td height="150" colspan="3" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="800" height="139" valign="top"><img src="images/banner copy.jpg" width="800" height="150" /></td>
</tr>
</table>
<%
String refno=request.getParameter("refno");
String sponsorname=request.getParameter("sponsorname");
out.println(sponsorname);//i am getting the values here.............
String sponsorsaddress=request.getParameter("sponsorsaddress");
out.println(sponsorsaddress);
String d=request.getParameter("sponsorsphoneno");
out.println(d);
int sponsorsphoneno=Integer.parseInt(d);
out.println(sponsorsphoneno);
String d1=request.getParameter("sponsorsfax");
int sponsorsfax=Integer.parseInt(d1);
out.println(sponsorsfax);
Connection con =null;
try
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     con=DriverManager.getConnection("jdbc:odbc:lsmsdsn","","");
PreparedStatement st=con.prepareStatement("update sponsordetails set sponsorname= ?,sponsorsaddress=?,sponsorsphoneno=?,sponsorsfax=? where refno=?");
st.setString(1,sponsorname);
out.println(sponsorname);
st.setString(2,sponsorsaddress);
st.setInt(3,sponsorsphoneno);
st.setInt(4,sponsorsfax);
st.setString(5,refno);
st.executeUpdate();
     out.println("record updated successfully"+"<A HREF='loginhtml.html'>login page</A>.");
finally {
     try {
          if (con !=null) {
          con.close();
     catch (SQLException se)
     out.println(se.getMessage());
%>
</body>
</html>
the database is not updating...its updating when i am giving values directly to update query..why?help me plzzz..
thanks in advance

ashish1234 wrote:
hi,
I am in the final touch of my course work in jsp.i did all the coding and tested..everything was working properly..after i did some modification in the structure of the page the update query is not working..i dont understand why?
i am attaching my old page and new page here...plz help me to solve this...
the database is not updating...its updating when i am giving values directly to update query..why?help me plzzz..With all that Java code in your JSPs, it doesn't look like you are in the final touch of learning JSP, but just at the beginning. Try to move all that java code into Servlets and JavaBeans. The JSP should be all about display, and nothing else.
What is your problem? I don't know. All that unformatted code is un-readable. On top of being scriptlet code which is hard enough to read.
You should search the logs to see if there is an error message hidden in there. That is one of the major problems with putting regular Java code in JSPs, the error messages get hidden, and become near impossible to translate.

Similar Messages

  • Code is not working check for solution . The code is not working after look up table.

    In this code i am multiplying two binary images , one is a rectangle and another is an image. i am getting the rectangle, but not the image. The image part is not working after the look up table. Waiting for the solution
    Attachments:
    binary morphology.vi ‏33 KB

    Hey.  I'm thinking the problem is in theis block:
    LOOP AT C_T_DATA INTO WA_MC17I30HDR.
       READ TABLE LT_AFIH
         WITH KEY AUFNR = WA_MC17I30HDR-AUFNR
         INTO WA_AFIH BINARY SEARCH.
       IF SY-SUBRC = 0.
         WA_MC17I30HDR-ZZNPLDA = WA_MHIS-NPLDA.
         MODIFY C_T_DATA FROM WA_MC17I30HDR.
    ENDIF.
    ENDLOOP.
    You are reading LT_AFIH into WA_AFIH.  But then you are assigning NPLDS from WA_MHIS. From what I can see, WA_MHIS hasn't been filled with anything.  Try changing:
         WA_MC17I30HDR-ZZNPLDA = WA_MHIS-NPLDA.
    To:
         WA_MC17I30HDR-ZZNPLDA = WA_AFIH-NPLDA.
    Hope that does the trick.
    Thanks
    Edited by: Siboda_Eric on May 26, 2010 3:49 PM

  • Sound not working after some time

    I am using pavilion g6 laptop. Nowadays my laptop sound stops working after some time of use. I checked the drivers but everything seems to be ok. Please help what to do??

    Hi sushovanee,
    Welcome to the HP Forums!
    I would like to take a moment and thank you for using the forum, it is a great place to find answers. For you to have the best experience in the HP forum, I would like to direct your attention to the HP Forums Guide First Time Here? Learn How to Post and More.
    I grasp you have a G6 notebook and after a period of time you lose the sound.
    Have you done all your Windows updates?
    Have you ran The HP Support Assistant to aid with this difficulty.
    Has there been any recent changes to your system?
    To assist you I will need some more information.
    What exact model of G6 do you have?
    How Do I Find My Model Number or Product Number
    What Operating system are you running?
    Sparkles1
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos, Thumbs Up" on the bottom right to say “Thanks” for helping!

  • Why is my Apple ID not working after I've reset it, Why is my Apple ID not working after I've reset it

    Why is my Apple ID not working after I've reset it? After I change it the password icon pops up and I type the new password in and it says it's wrong? What's happening

    Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and Hold the Sleep/Wake Button and the Home Button at the Same Time...
    Wait for the Apple logo to Appear...
    Usually takes about 15 - 20 Seconds... ( But can take Longer...)
    Release the Buttons...

  • THE REDEMPTION CODE IS NOT WORKING  ..... WHY  ?

    `why  wont the redemption code work ?  i put it in and than put in the code and it comes back the code is not good  ...

    LTS505 are you entering the redemption code at http://www.adobe.com/getserial/?  If so please review Serial number retrieval process FAQ | Point-of-sale activation products - http://helpx.adobe.com/x-productkb/policy-pricing/serial-number-retrieval-process-faq.html.  If the redemption code is still failing then please contact our support team.

  • Back Button does not work after upgrade to F4.01, why?

    90% of the time, since my upgrade to Firefox 4.01, my Back Button (arrow) does not work. I know there's a referring page and it hasn't opened a new window. Ideas?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    In Firefox 4 you can use one of these to start in <u>[[Safe mode]]</u>:
    * Help > Restart with Add-ons Disabled
    * Hold down the Shift key while double clicking the Firefox desktop shortcut (Windows)
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • MBA 11 (2013) pinch zoom does not work after some time, how to fix it ?

    Recently I purchased MBA 11 (2013) model ( 4GB ram & 1.3 Ghz dual core). Although I use iPhone 5 & iPad 4 but never used mac. So when I found the track pad is capable of pinch zoom(along with other gesture) I was excited. But later I found after opening few apps (like safari, chrome etc) pinch zoom stop working . I need to restart in order to make it work again. Other gestures works fine just issue with the pinch zoom. Along with this issue I have some other questions as well
    1) How to fix this pinch zoom issue?
    2) I use eclipse for android development, but when I connect android phone/tablet - os crashes, no idea why?
    3) How to uninstall & update apps properly which was downloaded from web (like I installed x-code) ?
    4) I want to use mouse (i am comfortable) - I need to know whether right click, wheel, ling click & drag works perfectly.
    5) How to back up the os if something goes wrong I can retrieve from there ?

    Error 2, 4 (or -4), 6, 40, 1000, 9006
    Follow Troubleshooting security software. Often, uninstalling third-party security software will resolve these errors.
    There may be third-party software that modifies your default packet size in Windows by inserting a TcpWindowSize entry into your registry. Your default packet size being set incorrectly can cause these errors. Contact the manufacturer of the software that installed the packet size modification for assistance or follow this article by Microsoft: How to reset Internet Protocol (TCP/IP).
    Verify that access to ports 80 and 443 are allowed on your network.
    Verify that communication to albert.apple.com or photos.apple.com is not blocked by a firewall, or other Internet security setting.
    Discard the .ipsw file, open iTunes and attempt to download the update again. See the steps underAdvanced Steps > Rename, move, or delete the iOS software file (.ipsw) below for file locations.
    Restore your device while connected to a different network.
    Restore using a different computer.
    http://support.apple.com/kb/TS3694#error6

  • Short code is not working after new firmware updat...

    I am in USA on T-mobile network. I recently updtated my N80 to the latest firmware 4.07.XXX. Everything worked fined especially VoIP features. However, I used short cut code for example like #MIN# to get my min usage status for my acct. It sends the message but not receive back the message like it used to be. Is anybody have similar issue? None of the short code is working on my phone.
    My favorite N80 applications: Nokia Mobile Search, Smart2go Beta,
    S60 Internet Radio, Mobile Weather.
    N80ie Firmware: V 4.0707.0.7 (March 28, 2007).

    Hard reset your phone *#7370# 12345 reformat, lose all data and don't install apps on your memory card.
    ‡Thank you for hitting the Blue/Green Star button‡
    N8-00 RM 596 V:111.030.0609; E71-1(05) RM 346 V: 500.21.009

  • Close Tags and other code hints not working after installing Dreamweaver 2014

    I'm working on a windows machine.  All the code hinting features where working on previous installations, but they're not on 2014.  I'm not sure if it's a bug or something was changed and I have to turn the features on somewhere other than the Code Hints settings?

    Try re-starting CC2014.
    Nancy O.

  • My secutiry code is not working after installing IOs5. The phone has asked for a new code after intalling it and now the phone is bloqued.

    Problem with security code.

    If you're referrning to the passcode, it's normal for you to have to reenter the code after updating.  If you don't remember what you put in, you have to restore the phone as new, without using a backup.

  • Yahoo mail will not work after upgrading to Firefox 26, WHY?

    I can see my email, but I can't open it, delete it, or go to any other folders. I have reinstalled Firefox 3 times, restarted my computer every time, logged out and back into Yahoo. Nothing changes. Why does Firefox continually screw something up every time it upgrades? I just want the previous version back without losing all my saved passwords and bookmarks!
    WIN XP SP3

    As you've probably noticed, Yahoo! has been making a lot of email changes lately. Users who are using an older bookmark to access Yahoo! mail have reported various glitches. Try accessing your mail using one of these:
    * Yahoo home page: https://www.yahoo.com/
    * My Yahoo page: https://my.yahoo.com/
    * Generic mail redirect: https://mail.yahoo.com/
    Make sure to bookmark the new address if it works.
    More generally, when you have a problem with one particular site that previously worked fine, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    Alternately, you also can clear Firefox's cache completely using:
    orange Firefox button (or Tools menu) > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now"
    If you have a large hard drive, this might take a few minutes.
    (2) Remove the site's cookies (save any pending work first). While viewing a page on the site, try either:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    In the dialog that opens, you can remove the site's cookies individually.
    Then try reloading the page. Does that help?

  • BC4j/JSP Application not responding after some time - when deployed on 9ias

    Hi,
    We are using BC4j/jsp application on 9ias. The application is not responding
    after some time. We have installed 9ias on PIII(384MB RAM). We tried to accesses
    with 10 users, and server is not responding to BC4J/JSP application.
    However the server could able to publish the JSP pages with standerad JDBC code even after that.
    many many thanks in advance
    null

    When the application deployed by BC4J/JSP not responding, does the sample JSP application still works? i.e. does any other application respond? Does 1 user respond? Is the database source (JDBC), running Oracle 8.1.7? What is the platform running the database (e.g. local NT database)?

  • BC4j/JSP Application not responding after some time - when deployed on 9ias BC4j/JSP

    Hi,
    We are using BC4j/jsp application on 9ias. The application is not responding
    after some time. We have installed 9ias on PIII(384MB RAM). We tried to accesses
    with 10 users, and server is not responding to BC4J/JSP application.
    However the server could able to publish the JSP pages with standerad JDBC code even after that.
    Please....help us.........
    many many thanks in advance

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Is there any mechanism that cleans up these connections (back down to the initial or some other minimum I would guess) or do they hang around until either the app server or database shuts down?<HR></BLOCKQUOTE>
    There is currently no mechanism for reducing the connection pool size after a period of high activity. Recently this has been frequently requested and as such will be implemented in the next production release.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>We have verified this in manual testing. However, when the load tool script exits it doesn't seem to release resources. We know this because we keep seeing our database connections go up and up as more tests are run. Further, we also seem to see more than one connection per "virtual user". For example, when I connect 5 users to the app in manual testing, I get 5 connections. But, when we run a test using the tool, we get 395 database sessions for 200 users. We are having a bit of difficulty understanding why the behavior is different.<HR></BLOCKQUOTE>
    Assuming that the you are performing your manual testing against the same instance of the application on which you are performing your load testing, I would assume that the connections are being released to the pool at the end of the request. One possible reason for the approximate 2:1 ratio between connections and virtual users may be BC4J's use of internal connections. What version of BC4J are you using?
    BC4J requires an internal connection to support state management and spill to disk. The internal connections are pooled with the transaction connection and only held for the duration of the persistence operation. However, if the web server is very busy then a large number of synchronous persistence requests may be received which would explain the eventual 2:1 ratio in the pool's high water mark.
    If the user start times and think times are staggered in order to reduce the incidence of synchronous persistence requests does the ratio of connections to web sessions stabilize at some lower number (i.e. 1.5:1)

  • Some keybaord keys not working after suspect virus on Tecra A

    Apostrophe, delete, semicolon and end keys not working after a suspected virus attack. I found record of the same problem on the net but apparently this guy fixed his problem after he found scroll lock or num lock on.
    This is not the case here but there is something going on with numlock - register shows 2 and not 0. change to 0 but when reboot back to 2 again.
    Suspect changed back by bios. I thought i couldnt get to bios because DEL key not working but found ESC works.
    Tried to reset default values for bios but then cannot save and exit as this required the END key to work.
    I was running XP at the time of the (suspected) attack and could not rectify the problem so put the computer back to the OEM status which i hoped would help - it did not, same problem so rather than install all the software on the computer again with XP i upgraded to Windows7 - fresh install.
    Still keys do not work - it was a real pain to start with as my computer was set up to ctl+alt+del to log in and i had to do this with on screen keyboard - XP - this also showed that numlock was on before and after windows boot.
    The reason i suspect a virus - my wife was watching one of her tv shows on line from home country (another toshiba laptop) and i needed to use that laptop for something else so i asked her to use mine - later on we turned the laptops off and in the morning turned tham back on again, the other laptop with AVG virus protection flagged several hits and this one with (FAMOUS and completely up to date) Norton flagged nothing - once i got into it using on screen keyboard.
    Problems with this computer was found after scanning with a different antivirus.
    Anyway - i am left with 4 keys that do not work on my keyboard (actually they did work after i logged into the computer for the first time but i had to hold them in for a long time - and then next time i rebooted, not work at all and havent ever since)
    Any assistance here would be greatly appreciated, i have been working on this all weekend with no joy at all.
    Thanks in advance.

    Thanks Xardas,
    I have essentially done both - tried Toshiba OEM status found on a small partition of the toshi hard drive - no good - then did a fresh install of Windows 7 - still no good
    You know - as cunning as it sounds - i cannot reload the default settings in BIOS as it requires the END key to work so i can Save & Exit - all i can do is Exit Without Save - i sort of feel snookered at the moment.
    Toshiba got back to me today and said that i have tried everything they would have (yeah for sure) and to take my machine into a service centre for a hardware check - yeah right on boys!
    Check out this guys post below found on Kioskea.net - getting close to a year ago...
    ms ml - Nov 10, 2009 12:52am GMT
    Hi there, I was hoping that you might be able to help me with the problem that I seem to be having with my Toshiba Satellite Laptop Keyboard too. For a few days now I havent been able to use a few of the keys on my keyboard, including (1) delete (the backspace key is still working though), (2) colon/semicolon, (3) apostrophe/quotation marks and (4) end (the home and PgUp and PgDn keys are still working though). Any suggestions?
    Identical to my problem....obviously this guy had the same problem as well...see below - same thread.
    yab - Feb 9, 2010 4:47am GMT
    hi did you ever figure this out? i have the same exact problem...
    However, i was not able to solve my problem the way this guy did - my scroll lock is not activated - it seems to work ok (on and off) i tested it using Excel to move around the cells.
    yab ms ml - Feb 9, 2010 7:57am GMT
    Nevermind. For me it was scroll lock. My apostrophe, semicolon, and delete keys are alive and working again. I hope you have the same easy fix.
    Incidently - never hear from the first guy again - probably ended up being his scroll lock.
    all sugestions welcome - sorry my smily face has no eyes -) guess why!

  • Why this code is not working??? java script

    gen_validatorv2.js
         JavaScript Form Validator
    Version 2.0.2
         Copyright 2003 JavaScript-coder.com. All rights reserved.
         You use this script in your Web pages, provided these opening credit
    lines are kept intact.
         The Form validation script is distributed free from JavaScript-Coder.com
         You may please add a link to JavaScript-Coder.com,
         making it easy for others to find this script.
         Checkout the Give a link and Get a link page:
         http://www.javascript-coder.com/links/how-to-link.php
    You may not reprint or redistribute this code without permission from
    JavaScript-Coder.com.
         JavaScript Coder
         It precisely codes what you imagine!
         Grab your copy here:
              http://www.javascript-coder.com/
    function Validator(frmname)
    this.formobj=document.forms[frmname];
         if(!this.formobj)
         alert("BUG: couldnot get Form object "+frmname);
              return;
         if(this.formobj.onsubmit)
         this.formobj.old_onsubmit = this.formobj.onsubmit;
         this.formobj.onsubmit=null;
         else
         this.formobj.old_onsubmit = null;
         this.formobj.onsubmit=form_submit_handler;
         this.addValidation = add_validation;
         this.setAddnlValidationFunction=set_addnl_vfunction;
         this.clearAllValidations = clear_all_validations;
    function set_addnl_vfunction(functionname)
    this.formobj.addnlvalidation = functionname;
    function clear_all_validations()
         for(var itr=0;itr < this.formobj.elements.length;itr++)
              this.formobj.elements[itr].validationset = null;
    function form_submit_handler()
         for(var itr=0;itr < this.elements.length;itr++)
              if(this.elements[itr].validationset &&
         !this.elements[itr].validationset.validate())
              return false;
         if(this.addnlvalidation)
         str =" var ret = "+this.addnlvalidation+"()";
         eval(str);
    if(!ret) return ret;
         return true;
    function add_validation(itemname,descriptor,errstr)
    if(!this.formobj)
         alert("BUG: the form object is not set properly");
              return;
         }//if
         var itemobj = this.formobj[itemname];
    if(!itemobj)
         alert("BUG: Couldnot get the input object named: "+itemname);
              return;
         if(!itemobj.validationset)
         itemobj.validationset = new ValidationSet(itemobj);
    itemobj.validationset.add(descriptor,errstr);
    function ValidationDesc(inputitem,desc,error)
    this.desc=desc;
         this.error=error;
         this.itemobj = inputitem;
         this.validate=vdesc_validate;
    function vdesc_validate()
    if(!V2validateData(this.desc,this.itemobj,this.error))
    this.itemobj.focus();
              return false;
    return true;
    function ValidationSet(inputitem)
    this.vSet=new Array();
         this.add= add_validationdesc;
         this.validate= vset_validate;
         this.itemobj = inputitem;
    function add_validationdesc(desc,error)
    this.vSet[this.vSet.length]=
         new ValidationDesc(this.itemobj,desc,error);
    function vset_validate()
    for(var itr=0;itr<this.vSet.length;itr++)
         if(!this.vSet[itr].validate())
              return false;
         return true;
    function validateEmailv2(email)
    // a very simple email validation checking.
    // you can add more complex email checking if it helps
    if(email.length <= 0)
         return true;
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    var regexp_user=/^\"?[\w-_\.]*\"?$/;
    if(splitted[1].match(regexp_user) == null) return false;
    if(splitted[2] != null)
    var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
    if(splitted[2].match(regexp_domain) == null)
         var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
         if(splitted[2].match(regexp_ip) == null) return false;
    }// if
    return true;
    return false;
    function V2validateData(strValidateStr,objValue,strError)
    var epos = strValidateStr.search("=");
    var command = "";
    var cmdvalue = "";
    if(epos >= 0)
    command = strValidateStr.substring(0,epos);
    cmdvalue = strValidateStr.substr(epos+1);
    else
    command = strValidateStr;
    switch(command)
    case "req":
    case "required":
    if(eval(objValue.value.length) == 0)
    if(!strError || strError.length ==0)
    strError = objValue.name + " : Required Field";
    }//if
    alert(strError);
    return false;
    }//if
    break;
    }//case required
    case "maxlength":
    case "maxlen":
    if(eval(objValue.value.length) > eval(cmdvalue))
    if(!strError || strError.length ==0)
    strError = objValue.name + " : "+cmdvalue+" characters maximum ";
    }//if
    alert(strError + "\n[Current length = " + objValue.value.length + " ]");
    return false;
    }//if
    break;
    }//case maxlen
    case "minlength":
    case "minlen":
    if(eval(objValue.value.length) < eval(cmdvalue))
    if(!strError || strError.length ==0)
    strError = objValue.name + " : " + cmdvalue + " characters minimum ";
    }//if
    alert(strError + "\n[Current length = " + objValue.value.length + " ]");
    return false;
    }//if
    break;
    }//case minlen
    case "alnum":
    case "alphanumeric":
    var charpos = objValue.value.search("[^A-Za-z0-9]");
    if(objValue.value.length > 0 && charpos >= 0)
    if(!strError || strError.length ==0)
    strError = objValue.name+": Only alpha-numeric characters allowed ";
    }//if
    alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
    return false;
    }//if
    break;
    }//case alphanumeric
    case "num":
    case "numeric":
    var charpos = objValue.value.search("[^0-9]");
    if(objValue.value.length > 0 && charpos >= 0)
    if(!strError || strError.length ==0)
    strError = objValue.name+": Only digits allowed ";
    }//if
    alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
    return false;
    }//if
    break;
    }//numeric
    case "alphabetic":
    case "alpha":
    var charpos = objValue.value.search("[^A-Za-z]");
    if(objValue.value.length > 0 && charpos >= 0)
    if(!strError || strError.length ==0)
    strError = objValue.name+": Only alphabetic characters allowed ";
    }//if
    alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
    return false;
    }//if
    break;
    }//alpha
              case "alnumhyphen":
    var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
    if(objValue.value.length > 0 && charpos >= 0)
    if(!strError || strError.length ==0)
    strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
    }//if
    alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
    return false;
    }//if                
                   break;
    case "email":
    if(!validateEmailv2(objValue.value))
    if(!strError || strError.length ==0)
    strError = objValue.name+": Enter a valid Email address ";
    }//if
    alert(strError);
    return false;
    }//if
    break;
    }//case email
    case "lt":
    case "lessthan":
    if(isNaN(objValue.value))
    alert(objValue.name+": Should be a number ");
    return false;
    }//if
    if(eval(objValue.value) >= eval(cmdvalue))
    if(!strError || strError.length ==0)
    strError = objValue.name + " : value should be less than "+ cmdvalue;
    }//if
    alert(strError);
    return false;
    }//if
    break;
    }//case lessthan
    case "gt":
    case "greaterthan":
    if(isNaN(objValue.value))
    alert(objValue.name+": Should be a number ");
    return false;
    }//if
    if(eval(objValue.value) <= eval(cmdvalue))
    if(!strError || strError.length ==0)
    strError = objValue.name + " : value should be greater than "+ cmdvalue;
    }//if
    alert(strError);
    return false;
    }//if
    break;
    }//case greaterthan
    case "regexp":
                   if(objValue.value.length > 0)
         if(!objValue.value.match(cmdvalue))
         if(!strError || strError.length ==0)
         strError = objValue.name+": Invalid characters found ";
         }//if
         alert(strError);
         return false;
         }//if
    break;
    }//case regexp
    case "dontselect":
    if(objValue.selectedIndex == null)
    alert("BUG: dontselect command for non-select Item");
    return false;
    if(objValue.selectedIndex == eval(cmdvalue))
    if(!strError || strError.length ==0)
    strError = objValue.name+": Please Select one option ";
    }//if
    alert(strError);
    return false;
    break;
    }//case dontselect
    }//switch
    return true;
         Copyright 2003 JavaScript-coder.com. All rights reserved.
    example.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Example for Validator</title>
    <script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script>
    </head>
    <body>
    <form action="" name="myform" >
    <table cellspacing="2" cellpadding="2" border="0">
    <tr>
    <td align="right">First Name</td>
    <td><input type="text" name="FirstName"></td>
    </tr>
    <tr>
    <td align="right">Last Name</td>
    <td><input type="text" name="LastName"></td>
    </tr>
    <tr>
    <td align="right">EMail</td>
    <td><input type="text" name="Email"></td>
    </tr>
    <tr>
    <td align="right">Phone</td>
    <td><input type="text" name="Phone"></td>
    </tr>
    <tr>
    <td align="right">Address</td>
    <td><textarea cols="20" rows="5" name="Address"></textarea></td>
    </tr>
    <tr>
    <td align="right">Country</td>
    <td>
         <SELECT name="Country">
              <option value="" selected>[choose yours]
              <option value="008">Albania
              <option value="012">Algeria
              <option value="016">American Samoa
              <option value="020">Andorra
              <option value="024">Angola
              <option value="660">Anguilla
              <option value="010">Antarctica
              <option value="028">Antigua And Barbuda
              <option value="032">Argentina
              <option value="051">Armenia
              <option value="533">Aruba     
         </SELECT>
         </td>
    </tr>
    <tr>
    <td align="right"></td>
    <td><input type="submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    <script language="JavaScript" type="text/javascript">
    //You should create the validator only after the definition of the HTML form
    var frmvalidator = new Validator("myform");
    frmvalidator.addValidation("FirstName","req","Please enter your First Name");
    frmvalidator.addValidation("FirstName","maxlen=20",
         "Max length for FirstName is 20");
    frmvalidator.addValidation("FirstName","alpha");
    frmvalidator.addValidation("LastName","req");
    frmvalidator.addValidation("LastName","maxlen=20");
    frmvalidator.addValidation("Email","maxlen=50");
    frmvalidator.addValidation("Email","req");
    frmvalidator.addValidation("Email","email");
    frmvalidator.addValidation("Phone","maxlen=50");
    frmvalidator.addValidation("Phone","numeric");
    frmvalidator.addValidation("Address","maxlen=50");
    frmvalidator.addValidation("Country","dontselect=0");
    </script>
    </body>
    </html>
    documentation.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
         <title>JavaScript Form Validator Documentation</title>
    <Style>
    BODY, P,TD{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 10pt }
    H1{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 18pt; color : #000066}
    H3{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 12pt; color : #000066 }
    A{font-family: Arial,Verdana,Helvetica, sans-serif;}
    B {     font-family : Arial, Helvetica, sans-serif;     font-size : 12px;     font-weight : bold;}
    CODE {font-family : Courier,monospace;font-size: 10pt;color : #800000;}
    CODE.htm {font-family : "Courier New", Courier, monospace;     font-size : x-small;     color : #000080;}
    </Style>
    </head>
    <body>
    <center>
    <table cellspacing="2" cellpadding="2" border="0" width="600">
    <tr><td>
         <h1>JavaScript Form Validations Made Easy!</h1>
         <h3>Documentation for JavaScript Form Validator</h3>
         <HR size=1>
         <P>
         The Form validation script is distributed free from JavaScript-Coder.com<br>
         You can use the script in your web pages for free.
         </P>
         <P>
         You may please add a link to JavaScript-Coder.com,
         making it easy for others to find this script.<br>
         Checkout the <A href="http://www.javascript-coder.com/links/how-to-link.php
         target="_blank">Give a Link & Get a Link!</A> page.
         </P>
         <P>
         <B>JavaScript Coder</B><br>
         It precisely codes what you imagine!<br>
         Grab your copy here: http://www.javascript-coder.com
         </P>
         <HR size=1>
         <P>
         Using client side JavaScript is an efficient way to validate the user input
         in web applications. When there are many fields in the form, the JavaScript
         validation becomes too complex.
         </P>
         <P>
    The JavaScript class presented here makes the form validations many times easier.
         </P>
         <P>
         The idea is to create a set of "validation descriptors" associated with each element
         in a form. The "validation descriptor" is nothing but a string specifying the type of
         validation to be performed.
         </P>
         <P>
         Each field in the form can have 0, 1, or more validations. For example, the input should
         not be empty, should be less than 25 chars, should be alpha-numeric, etc
         </P>
         You can associate a set of validation descriptors for each input field in the form.
         <a name="3"></a>
         <h3>Using The Script</h3>
         1.Include gen_validatorv2.js in your html file just before closing the HEAD tag<br><br>
         <CODE>
         <script language="JavaScript" src="gen_validatorv2.js" type="text/javascript"></script><BR>
         </head><BR>
         </CODE><br>
         2. Just after defining your form,
         Create a form validator object passing the name of the form<br><br>
         <CODE class='htm'>
          <FORM name='myform' action=""><BR>
          <!----Your input fields go here --><BR>
          </FORM><BR>
         </CODE><CODE>
          <SCRIPT language="JavaScript"><BR>
          var frmvalidator  = new Validator("myform");<BR>
         </CODE>
         <br>
         <br>
         3. Now add the validations required<br><br>
         <CODE>
              frmvalidator.addValidation("FirstName","alpha");
         </CODE><br><br>
         the first argument is the name of the field and the second argument is the
         validation descriptor, which specifies the type of validation to be performed.<br>
         You can add any number of validations.The list of validation descriptors are provided
         at the end of the documentation.<br>
         The optional third argument is the error string to be displayed if the validation
         fails.<br>
         <br>
         <CODE>
              frmvalidator.addValidation("FirstName","alpha");<br>
              frmvalidator.addValidation("FirstName","req","Please enter your First Name");<br>
              frmvalidator.addValidation("FirstName","maxlen=20",<br>
                   "Max length for FirstName is 20");          <br>
         </CODE>     <br>
         <br>
         4. Similarly, add validations for the fields where validation is required.<br>
         That's it! You are ready to go.
         <A name="3"></A>
         <h3>Example</h3>
         The example below will make the idea clearer<br>
         <CODE class="htm">
                   <form action="" name="myform" ><BR>
                   <table cellspacing="2" cellpadding="2" border="0"><BR>
                   <tr><BR>
                     <td align="right">First Name</td><BR>
                     <td><input type="text" name="FirstName"></td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right">Last Name</td><BR>
                     <td><input type="text" name="LastName"></td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right">EMail</td><BR>
                     <td><input type="text" name="Email"></td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right">Phone</td><BR>
                     <td><input type="text" name="Phone"></td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right">Address</td><BR>
                     <td><textarea cols="20" rows="5" name="Address"></textarea></td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right">Country</td><BR>
                     <td><BR>
                          <SELECT name="Country"><BR>
                             <option value="" selected>[choose yours]<BR>
                             <option value="008">Albania<BR>
                             <option value="012">Algeria<BR>
                             <option value="016">American Samoa<BR>
                             <option value="020">Andorra<BR>
                             <option value="024">Angola<BR>
                             <option value="660">Anguilla<BR>
                             <option value="010">Antarctica<BR>
                             <option value="028">Antigua And Barbuda<BR>
                             <option value="032">Argentina<BR>
                             <option value="051">Armenia<BR>
                             <option value="533">Aruba     <BR>
                         </SELECT><BR>
                        </td><BR>
                   </tr><BR>
                   <tr><BR>
                     <td align="right"></td><BR>
                     <td><input type="submit" value="Submit"></td><BR>
                   </tr><BR>
                   </table><BR>
                   </form><BR>
                   </CODE><CODE>
                   <script language="JavaScript" type="text/javascript"><BR>
                    var frmvalidator = new Validator("myform");<BR>
                    frmvalidator.addValidation("FirstName","req","Please enter your First Name");<BR>
                    frmvalidator.addValidation("FirstName","maxlen=20",<BR>
                        "Max length for FirstName is 20");<BR>
                    frmvalidator.addValidation("FirstName","alpha");<BR>
                    <BR>
                    frmvalidator.addValidation("LastName","req");<BR>
                    frmvalidator.addValidation("LastName","maxlen=20");<BR>
                    <BR>
                    frmvalidator.addValidation("Email","maxlen=50");<BR>
                    frmvalidator.addValidation("Email","req");<BR>
                    frmvalidator.addValidation("Email","email");<BR>
                    <BR>
                    frmvalidator.addValidation("Phone","maxlen=50");<BR>
                    frmvalidator.addValidation("Phone","numeric");<BR>
                    <BR>
                    frmvalidator.addValidation("Address","maxlen=50");<BR>
                    frmvalidator.addValidation("Country","dontselect=0");<BR>
                   </script><BR>     
         </CODE>
         <A name="4"></A>
         <h3>Some Additional Notes</h3>
         <LI type="disc">The form validators should be created only after defining the HTML form
         (only after the </form> tag. )<br>
         <LI type="disc">Your form should have a distinguished name.
         If there are more than one form
         in the same page, you can add validators for each of them. The names of the
         forms and the validators should not clash.
         <LI type="disc">You can't use the javascript onsubmit event of the form if it you are
         using this validator script. It is because the validator script automatically overrides the
         onsubmit event. If you want to add a custom validation, see the section below
         </LI>
         <A name="5"></A>
         <h3>Adding Custom Validation</h3>
         If you want to add a custom validation, which is not provided by the validation descriptors,
         you can do so. Here are the steps:
         <LI type="disc">Create a javascript function which returns true or false depending on the validation.<br>
         <CODE>
              function DoCustomValidation()<BR>
              {<BR>
                var frm = document.forms["myform"];<BR>
                if(frm.pwd1.value != frm.pwd2.value)<BR>
                {<BR>
                  alert('The Password and verified password does not match!');<BR>
                  return false;<BR>
                }<BR>
                else<BR>
                {<BR>
                  return true;<BR>
                }<BR>
              }<BR>
         </CODE><br>
         <LI type="disc">Associate the validation function with the validator object.<br>
         <CODE>
         frmvalidator.setAddnlValidationFunction("DoCustomValidation");
         </CODE><br>
         </LI>
         <P>
         The custom validation function will be called automatically after other validations.
         </P>
         <P>
         If you want to do more than one custom validations, you can do all those
         validations in the same function.
         </P>
         <CODE>
              function DoCustomValidation()<BR>
              {<BR>
                var frm = document.forms["myform"];<BR>
                if(false == DoMyValidationOne())<BR>
                {<BR>
                  alert('Validation One Failed!');<BR>
                  return false;<BR>
                }<BR>
                else<BR>
                if(false == DoMyValidationTwo())<BR>
                {<BR>
                  alert('Validation Two Failed!');<BR>
                  return false;<BR>
                }<BR>
                else<BR>
                {<BR>
                  return true;<BR>
                }<BR>
              }<BR>
         </CODE><br>
         where DoMyValidationOne() and DoMyValidationTwo() are custom functions for
         validation.
         <A name="6"></A>
         <h3>Clear All Validations</h3>
         In some dynamically programmed pages, it may be required to change the validations in the
         form at run time. For such cases, a function is included which clears all validations in the
         validator object.<br><br>
         <CODE>
         frmvalidator.clearAllValidations();
         </CODE><br>
         <br>
         this function call clears all validations you set.<br>
         You will not need this method in most cases.
         <a name="7"></a>
         <h3>Table of Validation Descriptors</h3>     
    <table cellspacing="2" cellpadding="2" border="1" width="520px">
    <tr>
    <td><FONT face=Arial size=2>
         required<BR>
         req </FONT>
         </td>
    <td><FONT face=Arial size=2>The field should not be
    empty </FONT>
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>
         maxlen=???<BR>
         maxlength=???
         </td>
    <td><FONT face=Arial size=2>checks the length entered data to the maximum. For
    example, if the maximum size permitted is 25, give the validation descriptor as "maxlen=25"
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>
         minlen=???<BR>
         minlength=???
         </td>
    <td><FONT face=Arial size=2>checks the length of the entered string to the
    required minimum. example "minlen=5"
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>
         alphanumeric /<BR>
         alnum </FONT>
         </td>
    <td><FONT face=Arial size=2>Check the data if it
    contains any other characters other than alphabetic or numeric characters
    </FONT>
         </td>
    </tr>     
    <tr>
    <td><FONT face=Arial size=2>num <BR>
         numeric </FONT>
         </td>
    <td><FONT face=Arial size=2>Check numeric data
    </FONT>
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>alpha <BR>
         alphabetic </FONT>
         </td>
    <td><FONT face=Arial size=2>Check alphabetic data.
    </FONT>
         </td>
    </tr>     
    <tr>
    <td><FONT face=Arial size=2>email </FONT>
         </td>
    <td><FONT face=Arial size=2>The field is an email
    field and verify the validity of the data. </FONT>
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>lt=???<BR>
         lessthan=???
         </td>
    <td><FONT face=Arial size=2>
         Verify the data to be less than the value passed.
         Valid only for numeric fields. <BR>
         example: if the
    value should be less than 1000 give validation description as "lt=1000"
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>gt=???<BR>
         greaterthan=???     </td>
    <td><FONT face=Arial size=2>
         Verify the data to be greater than the value passed.
         Valid only for numeric fields. <BR>
         example: if the
    value should be greater than 10 give validation description as "gt=10"
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>regexp=??? </FONT>
         </td>
    <td><FONT face=Arial size=2>
         Check with a regular expression the value should match the regular expression.<BR>
         example: "regexp=^[A-Za-z]{1,20}$" allow up to 20 alphabetic
         characters.
         </td>
    </tr>
    <tr>
    <td><FONT face=Arial size=2>dontselect=?? </FONT>
         </td>
    <td><FONT face=Arial size=2>This
    validation descriptor is valid only for select input items (lists)
    Normally, the select list boxes will have one item saying 'Select One' or
    some thing like that. The user should select an option other than this
    option. If the index of this option is 0, the validation description
    should be "dontselect=0"
         </td>
    </tr>
    </table>
         <P>
              <table cellspacing="2" cellpadding="2" border="1" width="520">
              <tr>
              <td>
                   <B>NOTE:</B><br>
                   The HTML Form Wizard included in JavaScript Coder contains still more
                   number of validations
                   (comparison validations, check box & radio button validations and more)<br>
                   Using the wizard, you can add validations to your forms
                   without writing a single line of code! <br>
                   JavaScript Coder takes care of
                   generating the code and inserting the code in to the HTML file.<br>
                   <A href="http://www.javascript-coder.com/index.phtml
                   target="_blank">Read more about JavaScript Coder</A>
                   </td>
              </tr>
              </table>
         </P>
         <A name="8"></A>
         <h3>Example Page</h3>     
         See the <a href="example.html target="_blank"
         >JavaScript form validation example here</a>
    </td>
    </tr>
    <tr><td align="center">
         <HR><br>
         Copyright &copy; 2003 JavaScript-Coder.com. All rights reserved.
    </td></tr>
    </table>     
    </center>
    </body>
    </html>

    The code is not working because you made a mistake somewhere, duh! So figure out what (hint: firefox javascript console, it's your friend) and fix it!
    And next time when you post code: use the [ code ]  tags to pretty format your code, as it is now it's unreadable.
    http://forum.java.sun.com/help.jspa?sec=formatting

Maybe you are looking for