You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Vincent Lin <vi...@gmail.com> on 2007/06/26 12:40:53 UTC

[S2] onsubmit in tag

Hi!

I wrote

<s:form action="Admin_create" onsubmit="return (validateFields())">

in my JSP, but struts 2 rendered the following html:

<form id="Admin_create" name="Admin_create" onsubmit="return
(validateFields()); return true;" ...>

Why it renders onsubmit="return (validateFields()); return true;"
instead of onsubmit="return (validateFields())" ?
Can I make renders  onsubmit="return (validateFields())" only?

Thanks!

Re: [S2] onsubmit in tag

Posted by Vincent Lin <vi...@gmail.com>.
Hi Dave,

Thank you.
You are right.
There is an error in my validateFields() function.
It works now.
The "return true" in onsubmit has nothing to do with my problem.

Vincent

On 6/26/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Vincent Lin <vi...@gmail.com> wrote:
> > If you try it in a plain html form, you will know
> > the difference. That's really useful to use
> > onsubmit="return (validateFields())" in form
> > tag,
>
> Um... Yeah, I understand that. What I'm saying is:
>
> onsubmit="return validateFields(); return true;"
>
> will always return the value of the validateFields()
> function call; the trailing "return true;" will never
> happen.
>
> d.
>
>
>
>
>       ____________________________________________________________________________________
> Shape Yahoo! in your own image.  Join our Network Research Panel today!
> http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] onsubmit in tag

Posted by Dave Newton <ne...@yahoo.com>.
--- Vincent Lin <vi...@gmail.com> wrote:
> If you try it in a plain html form, you will know
> the difference. That's really useful to use 
> onsubmit="return (validateFields())" in form
> tag,

Um... Yeah, I understand that. What I'm saying is:

onsubmit="return validateFields(); return true;"

will always return the value of the validateFields()
function call; the trailing "return true;" will never
happen.

d.



      ____________________________________________________________________________________
Shape Yahoo! in your own image.  Join our Network Research Panel today!   http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] onsubmit in tag

Posted by Vincent Lin <vi...@gmail.com>.
If you try it in a plain html form, you will know the difference.
That's really useful to use onsubmit="return (validateFields())" in form
tag,
and validate all fields in validateFields() function (If you are not using
validators.).
Return true in validateFields() if all validations are passed.
Return false when there is something wrong in your input.


On 6/26/07, Dave Newton <ne...@yahoo.com> wrote:
>
> --- Vincent Lin <vi...@gmail.com> wrote:
> > For example, onsubmit="return (validateFields())" is
> > specified in html <form> tag. If the javascript
> > function validateFields() return true, the form will
> > submit, otherwise it won't.
> >
> > It works fine in struts 1.
> > But struts2 always add 'return true' in onsubmit
> > event. That causes validateFields() useless.
>
> Why / how? Once it hits a return it doesn't make any
> difference what's after it.
>
> d.
>
>
>
>
>
> ____________________________________________________________________________________
> Now that's room service!  Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel to find your fit.
> http://farechase.yahoo.com/promo-generic-14795097
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] onsubmit in tag

Posted by Dave Newton <ne...@yahoo.com>.
--- Vincent Lin <vi...@gmail.com> wrote:
> For example, onsubmit="return (validateFields())" is
> specified in html <form> tag. If the javascript 
> function validateFields() return true, the form will
> submit, otherwise it won't.
> 
> It works fine in struts 1.
> But struts2 always add 'return true' in onsubmit
> event. That causes validateFields() useless.

Why / how? Once it hits a return it doesn't make any
difference what's after it.

d.



 
____________________________________________________________________________________
Now that's room service!  Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel to find your fit.
http://farechase.yahoo.com/promo-generic-14795097

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] onsubmit in tag

Posted by Vincent Lin <vi...@gmail.com>.
I usually use onsubmit in form tag to do javascript validation.

For example, onsubmit="return (validateFields())" is specified in html
<form> tag.
If the javascript function validateFields() return true, the form will
submit, otherwise it won't.

It works fine in struts 1.
But struts2 always add 'return true' in onsubmit event.
That causes validateFields() useless.


On 6/26/07, yitzle <yi...@users.sourceforge.net> wrote:
>
> Um... Firstly, it does the same thing.
> I think if you move the code to the submit button it renders it as
> expected.
>
> On 6/26/07, Dave Newton <ne...@yahoo.com> wrote:
> > --- Vincent Lin <vi...@gmail.com> wrote:
> > > Why it renders onsubmit="return (validateFields());
> > > return true;"
> > > instead of onsubmit="return (validateFields())" ?
> > > Can I make renders  onsubmit="return
> > > (validateFields())" only?
> >
> > Probably that's what's in the template. I'm not sure
> > that it really matters, though.
> >
> > d.
> >
> >
> >
> >
> >
> ____________________________________________________________________________________
> > Building a website is a piece of cake. Yahoo! Small Business gives you
> all the tools to get online.
> > http://smallbusiness.yahoo.com/webhosting
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: [S2] onsubmit in tag

Posted by yitzle <yi...@users.sourceforge.net>.
Um... Firstly, it does the same thing.
I think if you move the code to the submit button it renders it as expected.

On 6/26/07, Dave Newton <ne...@yahoo.com> wrote:
> --- Vincent Lin <vi...@gmail.com> wrote:
> > Why it renders onsubmit="return (validateFields());
> > return true;"
> > instead of onsubmit="return (validateFields())" ?
> > Can I make renders  onsubmit="return
> > (validateFields())" only?
>
> Probably that's what's in the template. I'm not sure
> that it really matters, though.
>
> d.
>
>
>
>
> ____________________________________________________________________________________
> Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
> http://smallbusiness.yahoo.com/webhosting
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] onsubmit in tag

Posted by Dave Newton <ne...@yahoo.com>.
--- Vincent Lin <vi...@gmail.com> wrote:
> Why it renders onsubmit="return (validateFields());
> return true;"
> instead of onsubmit="return (validateFields())" ?
> Can I make renders  onsubmit="return
> (validateFields())" only?

Probably that's what's in the template. I'm not sure
that it really matters, though.

d.



       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org