hi,
am very new to ajax and js . i tried using ajax for server validation in my jsp. i also used js for client side validation
i have my js script for client side validation in a seperate file. i embedded the ajax code in the jsp itself.
the client side validation and the ajax code are working when i use them seperately.
but when i try to use them both , the client side validation is not taking place at all. my page is directly dispatched to the validation servlet in the server .
is it a problem to include two seperate js files in a single jsp file?
pls help me out!!
16 2196 acoder 16,027
Recognized Expert Moderator MVP
Without code, we can only guess. Show your code or a link to a test page.
this is the jsp page i tried
the script file i tried is this fun.js - function validateFormOnSubmit(theForm) {
-
var reason = "";
-
reason += validateUsername(theForm.id);
-
reason += validatePassword(theForm.Password,theForm.Password2);
-
-
-
if (reason != "") {
-
alert("" + reason);
-
return false;
-
}
-
-
return true;
-
}
-
-
-
function validateUsername(fld) {
-
var error = "";
-
var illegalChars = /\W/; // allow letters, numbers, and underscores
-
-
if (fld.value == "") {
-
fld.style.background = 'Yellow';
-
error = "Enter a Username !!.\n";
-
} else if ((fld.value.length < 5) || (fld.value.length > 15)) {
-
fld.style.background = 'Yellow';
-
error = "The username should be of atleast 5 characters.\n";
-
} else if (illegalChars.test(fld.value)) {
-
fld.style.background = 'Yellow';
-
error = "The username contains illegal characters.\n";
-
} else {
-
fld.style.background = 'White';
-
}
-
return error;
-
}
-
-
-
function validatePassword(fld2,fld2) {
-
var error = "";
-
var illegalChars = /[\W_]/; // allow only letters and numbers
-
-
if (fld1.value == "") {
-
fld1.style.background = 'Yellow';
-
error = "Pls Enter a Password.\n";
-
}else if(fld2.value == "") {
-
fld2.style.background = 'Yellow';
-
error = "Pls Enter the Password again.\n";
-
}else if ((fld1.value.length < 6) || (fld1.value.length > 15)) {
-
error = "The password should be atleast 6 chars \n";
-
fld1.style.background = 'Yellow';
-
}else if (illegalChars.test(fld1.value)) {
-
error = "The password contains illegal characters.\n";
-
fld1.style.background = 'Yellow';
-
} else if(fld1.value!=fld2.value)
-
error="The password in the two fields must match\n"
-
fld2.style.background="Yellow";
-
else {
-
fld.style.background = 'White';
-
}
-
return error;
-
}
this is the servlet - protected void doGet(HttpServletRequest request, HttpServletResponse response)
-
throws ServletException, IOException {
-
-
-
ResultSet rs;
-
String sql;
-
-
request.setCharacterEncoding("UTF-8");
-
-
-
Statement stmt ;
-
String name=request.getParameter("id").toString();
-
-
-
-
-
-
try {
-
//loading the driver
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
//connection object created using DriverManager class
-
//student_base is the name of the database
-
Connection connect =DriverManager.getConnection("jdbc:odbc:student_base");
-
-
-
-
-
stmt=connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
-
-
//creating prepared statement object pstm so that query can be sent to database
-
-
-
-
-
//execute method to execute the query
-
rs= stmt.executeQuery("SELECT PASSWORD FROM STUDENT_BASE"+" WHERE NAMES = '" + name + "'");
-
-
RequestDispatcher rd;
-
if(rs.next()) //username exists
-
{
-
response.setContentType("text/xml");
-
response.setHeader("Cache-Control", "no-cache");
-
response.getWriter().write("<valid>false</valid>");
-
-
//forwarding to the corresponding view
-
}
-
-
else //code when username does not exist
-
{
-
response.setContentType("text/xml");
-
response.setHeader("Cache-Control", "no-cache");
-
response.getWriter().write("<valid>true</valid>");
-
-
-
}
-
-
-
rs.close();
-
-
connect.close();
-
-
} catch(SQLException sqe) {
-
System.out.println(sqe.getMessage());
-
} catch(ClassNotFoundException cnf) {
-
System.out.println("Class not found error");
-
}
-
-
-
}
-
-
/** Handles the HTTP <code>POST</code> method.
-
* @param request servlet request
-
* @param response servlet response
-
*/
-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
-
throws ServletException, IOException {
-
-
ResultSet rs;
-
String sql;
-
-
response.setContentType("text/html;charset=UTF-8");
-
-
-
Statement stmt ;
-
String name=request.getParameter("id").toString();
-
String Password=request.getParameter("Password").toString().trim();
-
-
-
-
-
-
try {
-
//loading the driver
-
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-
-
//connection object created using DriverManager class
-
//student_base is the name of the database
-
Connection connect =DriverManager.getConnection("jdbc:odbc:student_base");
-
-
-
-
-
stmt=connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
-
-
//creating prepared statement object pstm so that query can be sent to database
-
-
-
-
-
//execute method to execute the query
-
rs= stmt.executeQuery("SELECT PASSWORD FROM STUDENT_BASE"+" WHERE NAMES = '" + name + "'");
-
-
RequestDispatcher rd;
-
-
if(rs.next()) //username exists
-
{
-
-
//add code to take to the next page
-
-
-
}
-
-
else {
-
PreparedStatement pstm=connect.prepareStatement("insert into student_base values(?,?)");
-
pstm.setString(1,name);
-
pstm.setString(2,Password);
-
//execute method to execute the query
-
pstm.executeUpdate();
-
-
rd=request.getRequestDispatcher("success.view");
-
-
-
-
rd.forward(request,response);
-
//closing the prepared statement and connection object
-
pstm.close();
-
-
}
-
rs.close();
-
connect.close();
-
-
} catch(SQLException sqe) {
-
System.out.println(sqe.getMessage());
-
} catch(ClassNotFoundException cnf) {
-
System.out.println("Class not found error");
-
}
-
-
}
-
-
acoder 16,027
Recognized Expert Moderator MVP
On line 73, change - <SCRIPT TYPE="TEXT/JAVASCIPT" SRC="fun.js"></SCRIPT>
to - <script type="text/javascript" src="fun.js"></script>
and see if that makes a difference.
nope !! i tried it!!no diff wotsoever......
pls help me out...i am stuck up with this for more than a day... iam having no bright ideas with my meagre knowledge of ajax and js.....
thanks for the effort though!!
acoder 16,027
Recognized Expert Moderator MVP
Do you see any errors when you submit?
the page is loading with a script error.. IE show the message that the page loaded with error... mozilla is showing no errors.... ajax is working alone fine anyway..
also everytime i change the focus from the textbox under question the" page has error" is intimated in the IE... so am not sure whether its a problem because of the ajax or the js .....
i tried including the client side js functions which i now hav in fun.js to the jsp itself along with ajax part.. in that case both of the validations are not working....
acoder 16,027
Recognized Expert Moderator MVP
What's the error message?
am talkin abt the error that is shown at the bottom most corner of the page to the left of the status bar in the browser..... it just shows page loaded with error and the alert symbol...no other indication..... my server is not throwing up any exception or anything in the server log...
acoder 16,027
Recognized Expert Moderator MVP
In IE, if you double click the icon, you should see the error message and line number. Are you sure there's nothing in the Firefox console?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Sokolov Yura |
last post by:
Django Model is wonderfull. But SQLObject more flexible (and powerfull,
as i think, and has already more db interfaces).
But Django Model is tied with Django, and using Django with another OO
mapping is not comfortable.
Why do not working together? I can't understand.
If you (Django and SQLObject) would, you'll beat everyone else in
efficiency (i mean ROR and maybe some Python's frameworks).
It is for all of Open Source. There a lot of...
|
by: David L Wright II |
last post by:
Does anyone know when building a msi file under VB.Net 2003, it would try to
install something from the VS 2005 Beta 1? I have both products installed.
Thanks,
|
by: Rod |
last post by:
Well, I've taken the plunge and gotten myself my first domain. (I've worked
on other peoples and of course at work, but never done my own domain.)
With this new project my family and I will likely work on it together. And
we'll be using FrontPage 2003. I would also like to use Visual Studio 2005
for those portions when appropriate (such as a members' only area), so I
would like to know how to make FP 2003 and Visual Studio 2005 work...
|
by: geshan |
last post by:
In php5 I am not able to use include funciton and header("location:"""
together please help.
|
by: Bill Gower |
last post by:
I have a webapp that uses the AjaxControlToolkit. The app and ajax works
fine when run within my dev server in Visual Studio 2005 but does not work
on IIS. Any Suggestions?
Bill
| |
by: buddyr |
last post by:
Hello,
I am having trouble with two combo boxes working together.
two tables table1 table2
table1 fields -number and name
table 2 fields -code and number
data in table one field number 1,2,3
data in table one field name Tom, Bob, Jim
data in table two field code 11,22,33,44,55,66,
data in table two field number 1,2,3,1,2,3
|
by: MimiMi |
last post by:
I'm trying to put together a http response header. It seems to work, except for that I don't get the data string added correctly!
I wouldn't be surprised if my problems have something to do with my still existing confusion over arrays and pointers in C since I'm still a newbie, but anyhow, here's the code:
#include <time.h>
#include <stdio.h>
#define WEBBUF_SIZE 32768
|
by: SavRak |
last post by:
Hi,
I seem to be having an issue linking my XML document and XML Schema together.
Both are not working, and do not seem to be validating when using:
http://tools.decisionsoft.com/schemaValidate/
Im not sure if what I have will work, or does work, as I can still output the XML via an XSLT fine :S
Ive attached my XML page and XML Schema, if someone could have a look I would be very grateful!
Thanks,
|
by: software4 |
last post by:
So I am not great at Javascript, but i have 2 scripts that i want to work with each other. When i use one by itself, they each work fine, but when i add them together it does not work.
I have a user form with a bunch of fields on it. If they choose an option on the drop down menu, some fields either show or disappear. Those fields have an "On Change" event that subtracts one field form another and gives us a total....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |