For Programmers: Free Programming Magazines  


Home > Archive > Java Help > October 2004 > How to validate the input field values before leaving the JSP page?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to validate the input field values before leaving the JSP page?
Arnold Peters

2004-10-13, 8:57 pm

I set up a jsp page (say: first.jsp) with a couple of input-/entryfields in a form.
After the user entered some values he clicks on the submit button.
Normally (if all values are acceptable) the user should be forwarded to the next page (next.jsp).
If (and only then) the values are wrong the user should stay on the current page and some
error messages should appear at the top of current jsp.

Thus what I need is a code execution BEFORE leaving the current page and not (only) when the
page is created.

How do I implement this with JavaServerPages (under JBoss) ?
Unfortuantely there is no command like

<form action="if (validate(this.formdata)==true) next.jsp else first.jsp">

Arnold

Bryce

2004-10-13, 8:57 pm

On Wed, 13 Oct 2004 23:07:20 +0200, apet10@hotmail.com (Arnold Peters)
wrote:

>I set up a jsp page (say: first.jsp) with a couple of input-/entryfields in a form.
>After the user entered some values he clicks on the submit button.
>Normally (if all values are acceptable) the user should be forwarded to the next page (next.jsp).
>If (and only then) the values are wrong the user should stay on the current page and some
>error messages should appear at the top of current jsp.
>
>Thus what I need is a code execution BEFORE leaving the current page and not (only) when the
>page is created.
>
>How do I implement this with JavaServerPages (under JBoss) ?
>Unfortuantely there is no command like
>
> <form action="if (validate(this.formdata)==true) next.jsp else first.jsp">


Many ways to do it.

1) If you are certain the user won't disable javascript, you can use
that.

or

2) in your next.jsp, check the values, if bad, send it back.

Struts has this built in with its validator framework.

--
now with more cowbell
Alex Kizub

2004-10-13, 8:57 pm

Arnold:
You mixed two confs. This question is for comp.lang.javascript
Anyway here is answer:
<html>
<form name=f onsubmit="
if (f.p.value=='1') f.action='m1.jsp';
else f.action='m2.jsp';
">
<SELECT NAME='p'>
<OPTION value=1>One
<OPTION value=2>Two
</SELECT>

<input type=submit>
</form>
</html>

Alex Kizub.
Arnold Peters wrote:

> I set up a jsp page (say: first.jsp) with a couple of input-/entryfields in a form.
> After the user entered some values he clicks on the submit button.
> Normally (if all values are acceptable) the user should be forwarded to the next page (next.jsp).
> If (and only then) the values are wrong the user should stay on the current page and some
> error messages should appear at the top of current jsp.
>
> Thus what I need is a code execution BEFORE leaving the current page and not (only) when the
> page is created.
>
> How do I implement this with JavaServerPages (under JBoss) ?
> Unfortuantely there is no command like
>
> <form action="if (validate(this.formdata)==true) next.jsp else first.jsp">
>
> Arnold


Sting

2004-10-15, 3:56 am

this kind of work should be done at the client side
use Javascript

"Arnold Peters" <apet10@hotmail.com> дÈëÓʼþ
news:ckk5e8$dvp$03$1@news.t-online.com...
> I set up a jsp page (say: first.jsp) with a couple of input-/entryfields

in a form.
> After the user entered some values he clicks on the submit button.
> Normally (if all values are acceptable) the user should be forwarded to

the next page (next.jsp).
> If (and only then) the values are wrong the user should stay on the

current page and some
> error messages should appear at the top of current jsp.
>
> Thus what I need is a code execution BEFORE leaving the current page and

not (only) when the
> page is created.
>
> How do I implement this with JavaServerPages (under JBoss) ?
> Unfortuantely there is no command like
>
> <form action="if (validate(this.formdata)==true) next.jsp else

first.jsp">
>
> Arnold
>



Tomer Ben-David

2004-10-27, 3:58 am

apet10@hotmail.com (Arnold Peters) wrote in message news:<ckk5e8$dvp$03$1@news.t-online.com>...
> I set up a jsp page (say: first.jsp) with a couple of input-/entryfields in a form.
> After the user entered some values he clicks on the submit button.
> Normally (if all values are acceptable) the user should be forwarded to the next page (next.jsp).
> If (and only then) the values are wrong the user should stay on the current page and some
> error messages should appear at the top of current jsp.
>
> Thus what I need is a code execution BEFORE leaving the current page and not (only) when the
> page is created.
>
> How do I implement this with JavaServerPages (under JBoss) ?
> Unfortuantely there is no command like
>
> <form action="if (validate(this.formdata)==true) next.jsp else first.jsp">
>
> Arnold


perhaps something like this

<form onSubmit="return somevalidation(this)">
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com