users
[Top] [All Lists]

Re: [cinjug-users] jsp form question

To: users@xxxxxxxxxx
Subject: Re: [cinjug-users] jsp form question
From: "Sam Corder" <samus@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 02 Apr 2004 16:19:11 +0000
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
Actually you don't need the else part there at all.  If you return a false
from a function in an onSubmit or onClick the action gets cancelled.  So all
you need to do is change your  function to look like:

                 if(thisForm.comp.value == '')
                 {
                         alert('Company name is required.');
                         thisForm.comp.focus();
                         return false;
                 }
                  ...
                  return true;

Also make sure you do the same validation on the server side.  Never trust the
client to send you good data.

-Sam Corder
Jason Kretzer/STAR BASE Consulting Inc. (JKretzer@xxxxxxxxxxxxxxx) wrote:
>
> OK, I have it now.  I used :
>
> //for the submit button
> onSubmit=validateFields();
>
> //then in validateFields I got the form and checked each field for a value
> and then submitted when all had a value, like so:
> var thisForm = document.forms[0];
>
>                 if(thisForm.comp.value == '')
>                 {
>                         alert('Company name is required.');
>                         thisForm.comp.focus();
>                         return;
>                 }
>                 else if(thisForm.desc.value == '')
>                 {
>                         alert('Short description is required.');
>                         thisForm.desc.focus();
>                         return;
>                 }
>                 else if(thisForm.addr.value == '')
>                 {
>                         alert('An address is required.');
>                         thisForm.addr.focus();
>                         return;
>                 }
>                 ///....etc.
>                 else
>                 {
>                         thisForm.method.value = 'POST';
>                         thisForm.action = 'FormProcessor?action=a';
>                         thisForm.submit();
>                 }
>
> Thanks for the help everyone.  My problem is that I did not know you could
> perform the commands in that last else in javascript.
>
> -Jason
>
>
>
>
> "Jason Kretzer/STAR BASE Consulting Inc." <JKretzer@xxxxxxxxxxxxxxx>
> 04/02/2004 09:00 AM
>
> To
> users@xxxxxxxxxx
> cc
>
> Subject
> [cinjug-users] jsp form question
>
>
>
>
>
>
>
> Good morning all,
>
> I have a question about form submission.  I have a jsp that has a form of
> about 12 input fields.  All of the fields are required to have something
> in them.  Is there a way to have a javascript to do this and then still
> POST the form to a servlet?
>
> Thanks,
>
> -Jason
>


<Prev in Thread] Current Thread [Next in Thread>