You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Silverio Wagner Silva(Secorp)" <ss...@itaonline.com.br> on 2003/05/02 17:01:38 UTC

Beginner question

Guys, 
 
I am trying to submit a form using a link, but it doesn´t work. I searched
for some similar solutions in this mail list but none of them worked well.
 
The code looks like this:
 
****************
<html:form action="/cadastro">
...
<html:link href="/site/cadastro.do"
onclick="form.submit();">Incluir</html:link>
...
</html:form>
 
*****************
 
Can anyone help me?
 
Silvério
 
 

Re: Beginner question

Posted by Ian Hunter <ih...@hunterweb.net>.
If you only have one form on the page, you can get away with

<html:form action="cadastro"/>
<!-- pretend there is a form bean associated with "cadastro" called
"strutsForm" -->
...

<html:link href="whatever" onlick="strutsForm.submit();">Hi
there</html:link>

the key is that struts names the form the same as it's associated ActionForm
from struts-config.

If you have multiple forms on the page, and they use the same action, you'll
have to use document.forms[xx].submit()

----- Original Message -----
From: "Silverio Wagner Silva(Secorp)" <ss...@itaonline.com.br>
To: <st...@jakarta.apache.org>
Sent: Friday, May 02, 2003 11:01 AM
Subject: Beginner question


Guys,

I am trying to submit a form using a link, but it doesn´t work. I searched
for some similar solutions in this mail list but none of them worked well.

The code looks like this:

****************
<html:form action="/cadastro">
...
<html:link href="/site/cadastro.do"
onclick="form.submit();">Incluir</html:link>
...
</html:form>

*****************

Can anyone help me?

Silvério




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


Re: Beginner question

Posted by "K.C. Baltz" <kc...@lollimail.com>.
Would this work just as well?

<a href="javascript:document.frames[0].submit()">link</a>

I've never been sure of the difference between onclick and 
href="javascript:" 

K.C.

Andrew Hill wrote:

>Your onclick should be "document.forms[0].submit()" and you dont want a
>normal href. I use "javascript: void(0);" in these situations.
>
>Heres one from my app (raw xhtml):
><a id="cancel" onclick="submitWithMethod('cancel',true); return false;"
>href="javascript: void(0);">
>
>The submitWithMethod() function you see in that is my own function that does
>lots of wierd stuff, fools around a bit with the forms action property and
>then call submit().
>
>So I guess in your case you would want something like:
><html:link href="javascript: void(0);"
>onclick="document.forms[0].submit();">Incluir</html:link>
>
>
>
>-----Original Message-----
>From: Silverio Wagner Silva(Secorp) [mailto:ssilva@itaonline.com.br]
>Sent: Friday, 2 May 2003 23:02
>To: 'struts-user@jakarta.apache.org'
>Subject: Beginner question
>
>
>Guys,
>
>I am trying to submit a form using a link, but it doesn´t work. I searched
>for some similar solutions in this mail list but none of them worked well.
>
>The code looks like this:
>
>****************
><html:form action="/cadastro">
>...
><html:link href="/site/cadastro.do"
>onclick="form.submit();">Incluir</html:link>
>...
></html:form>
>
>*****************
>
>Can anyone help me?
>
>Silvério
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>  
>


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


RE: Beginner question

Posted by Andrew Hill <an...@gridnode.com>.
Your onclick should be "document.forms[0].submit()" and you dont want a
normal href. I use "javascript: void(0);" in these situations.

Heres one from my app (raw xhtml):
<a id="cancel" onclick="submitWithMethod('cancel',true); return false;"
href="javascript: void(0);">

The submitWithMethod() function you see in that is my own function that does
lots of wierd stuff, fools around a bit with the forms action property and
then call submit().

So I guess in your case you would want something like:
<html:link href="javascript: void(0);"
onclick="document.forms[0].submit();">Incluir</html:link>



-----Original Message-----
From: Silverio Wagner Silva(Secorp) [mailto:ssilva@itaonline.com.br]
Sent: Friday, 2 May 2003 23:02
To: 'struts-user@jakarta.apache.org'
Subject: Beginner question


Guys,

I am trying to submit a form using a link, but it doesn´t work. I searched
for some similar solutions in this mail list but none of them worked well.

The code looks like this:

****************
<html:form action="/cadastro">
...
<html:link href="/site/cadastro.do"
onclick="form.submit();">Incluir</html:link>
...
</html:form>

*****************

Can anyone help me?

Silvério




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