There are various ways to tackle the problem. The bottom line is you don't
want to send bad data to the server and let server validate it. You can use
the code Oscar desribed, or more user friendly approach is to create bunches
of error images and display those images instead of using alert pop. It's
really annoy for the user to see things pop around, in addition, if he has
several mistyped fields, he won't be able to see it once for all.

Although consider other tips like using Maxlength to control the size of
textfield, validate  char or numbers, validate space between chars. For a
serious application, you also may need some HTML encoder and decoder class
at server side to deal with special charaters like *&$#. So the data sent to
DB is well format,and can also be correctly displayed on the client site.

Various places for reference http://www.javascript.com/
http://www.jsworld.com/

Dawei



-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Luciana Carone Biazoto
Sent: Friday, February 09, 2001 7:16 AM
To: [EMAIL PROTECTED]
Subject: Re: Querying a Database in JSP.


Hi, Oscar.
Is quite simple...
To check fi the fields are filled, you must use javascript.
Put in your button "onClick" a call to a method like this:

<input type="button" ... onClick="checkFields()" ... >

<script>

function checkFields() {
        if (document.myForm.myField1.value == "") {
                alert("Field1 must be filled.");
                document.myForm.myField1.focus();

        } else if (document.myForm.myField2.value == "") {
                alert("Field2 must be filled.");
                document.myForm.myField2.focus();

        } else {
                submit(); // Your form must submit to the page where you
have the bean
that authenticate in the database.
        }
}

</script>

Kisses,
Luciana.

-----Original Message-----
From: A mailing list about Java Server Pages specification andreference
[mailto:[EMAIL PROTECTED]]On Behalf Of Sello Mathibe
Sent: Friday, February 09, 2001 7:03 AM
To: [EMAIL PROTECTED]
Subject: Querying a Database in JSP.


> Hi. I've created a JSP login page where I've got a Username field and a
> Password field. I've created a table in my Access database, I've also
> created a DSN and can connect to it in my BEAN. Now my problem is that: I
> want to check if the user/client has entered some data on both fields, if
> he submit before he enters some data, I want to through an error message
> or alert in JavaScript. If something is entered on both fields, I want to
> validate that data from the database through the bean.
>
> Can somebody help me cause, I'm trying to create a huge application, but
> I'm stuck at the beginning!
> Thank You
> Oscar
###########################################

This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.
For more information, connect to http://www.F-Secure.com/

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to