You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Akshay Ahooja <ak...@gmail.com> on 2006/07/13 16:58:31 UTC

Calling a struts action from Javascript

Hi,

Does anyone know how to call a Struts action using Javacript...

I am using:
<html:form action+"...">

...

</html:form>


I know for regular form tags (<form>) you can use: document.formname.submit
()...

How would you do it for <html:form>? I have to use this because I am using
the Struts Bridge in Jetspeed-2...


Thanks,

Akshay

Re: Calling a struts action from Javascript

Posted by Bart Busschots <ba...@so-4pt.net>.
Hi,

If you do a 'view source' and have a look at the actual HTML that struts 
generates you'll see that is generates a form with an ID which is the 
same name as the form associated with the action in strutsconfig. Hence 
to submit the form from JS you need to so something like:

document.getElementById('nameOfForm').submit();

HTH,

Bart.

Akshay Ahooja wrote:
> Hi,
>
> Does anyone know how to call a Struts action using Javacript...
>
> I am using:
> <html:form action+"...">
>
> ...
>
> </html:form>
>
>
> I know for regular form tags (<form>) you can use: 
> document.formname.submit
> ()...
>
> How would you do it for <html:form>? I have to use this because I am 
> using
> the Struts Bridge in Jetspeed-2...
>
>
> Thanks,
>
> Akshay
>


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


Re: Calling a struts action from Javascript

Posted by Monkeyden <mo...@gmail.com>.
To elaborate on Frank's reply, the name of the form comes from the name
attribute of the <action-mapping> in the struts-config, but this value is
just a reference to the <form-bean> configuration.  Within the context of
the <action-mapping>, I might even call it a misnomer.  People new to struts
might be better served by a "bean", "form" or "action-form" attribute.
Anyway, it is what it is.

You could also reference it by using the it's index in the array of forms in
the DOM.  The first form encountered by the browser will have a 0 (zero)
index.  For example, the first form would be document.forms[0], the second,
document.forms[1], etc.  The former is obviously much more declarative.

Hope none of this confuses.


On 7/13/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> On Thu, July 13, 2006 10:58 am, Akshay Ahooja wrote:
> > Hi,
> >
> > Does anyone know how to call a Struts action using Javacript...
> >
> > I am using:
> > <html:form action+"...">
> >
> > ...
> >
> > </html:form>
> >
> >
> > I know for regular form tags (<form>) you can use:
> > document.formname.submit
> > ()...
> >
> > How would you do it for <html:form>? I have to use this because I am
> using
> > the Struts Bridge in Jetspeed-2...
>
> You can do it exactly the same way... <html:form> renders a <form>
> underneath.  IIRC, the name of the form is the value of the action
> attribute, but check the source of a page using <html:form> to be sure.
>
> > Akshay
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM: fzammetti
> Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Java Web Parts -
> http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Calling a struts action from Javascript

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Thu, July 13, 2006 10:58 am, Akshay Ahooja wrote:
> Hi,
>
> Does anyone know how to call a Struts action using Javacript...
>
> I am using:
> <html:form action+"...">
>
> ...
>
> </html:form>
>
>
> I know for regular form tags (<form>) you can use:
> document.formname.submit
> ()...
>
> How would you do it for <html:form>? I have to use this because I am using
> the Struts Bridge in Jetspeed-2...

You can do it exactly the same way... <html:form> renders a <form>
underneath.  IIRC, the name of the form is the value of the action
attribute, but check the source of a page using <html:form> to be sure.

> Akshay

Frank

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

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