You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by An...@fiducia.de on 2006/09/12 13:20:25 UTC

Submitting forms with javascript in struts

Hello,

I do have a problem, because I don't know how to submit a form with javascript
in struts.

Normally, I'm submitting forms like this:

<html:form action="somepath">
<html:submit property="myvalue" value="send">
</html:form>

I'm receiving the value with the getter-method getMyvalue() of the appropriate
ActionForm.



This time, I want to submit the form with a

<a href=javascript:dosubmit("value")>Some text</a>


dosubmit is a function like

<script>
dosubmit(what)
{
      document.formname.value=what;
      document.formname.submit();
}
</script>


The browser submits the form (I'm getting no javascript error), but I don't get
the value of document.formname.value.


I would be glad to get some help,
kind regards,
Andreas Hartmann


BTW:
Is there a way to send another value in the html:submit - button as this, which
is displayed to the user?


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


Re: Submitting forms with javascript in struts [*]

Posted by An...@fiducia.de.
Hello!

Unfortunately the last posted solution didn't work either. That's why I'm using
another way now to get the form submitted via href and javascript. The
javascript function calls the existing submit-button and does a click:

document.myform.target="mytarget";
document.myform.myproperty.value="desired_value";
document.myform.myproperty.click();

That's the way it works.

Caveat: You have to take care, that the old value of the submit-button has to be
written back :-).



Kind regards,
Andreas Hartmann


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


Re: Submitting forms with javascript in struts [*]

Posted by Puneet Lakhina <pu...@gmail.com>.
On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de> wrote:
>
> On 9/12/06, puneet.lakhina wrote:
> >>On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de>
> wrote:
> >>
> >> On 9/12/06, puneet.lakhina wrote:
> >>
> > >>  On 9/12/06, Andreas.Hartmann@fiducia.de <Andreas.Hartmann@fiducia.de
> >
> wrote:
> > >>>
> > >>>
> > >>> Hello,
> > >>>
> > >>> I do have a problem, because I don't know how to submit a form with
> > >>> javascript
> > >>> in struts.
> > >>>
> > >>> Normally, I'm submitting forms like this:
> > >>>
> > >>> <html:form action="somepath">
> > >>> <html:submit property="myvalue" value="send">
> > >>> </html:form>
> > >>>
> > >>> I'm receiving the value with the getter-method getMyvalue() of the
> > >>> appropriate
> > >>> ActionForm.
> > >>>
> > >>>
> > >>>
> > >>> This time, I want to submit the form with a
> > >>>
> > >>> <a href=javascript:dosubmit("value")>Some text</a>
> > >>
> >
> >
> > I think you should be doing it onclick
> > <a href="" onclick='doSubmit("value")'>Some Text</a>
>
> Hmm, doesn't work at all. I can't see any value in getMyvalue().
>
> > And could you please make your mail client use Re for reply to a message
> > instead of Antwort. Helps in following the thread.
>
> I have to do all the quoting manually, because I hve to use notes, which
> isn't
> able to quote at all as it is usually done in the internet. I'll do my
> best :-).
>
> >>
> >> > Assuming your property name is myvalue
> >> > try this is your java script
> >> >
> > >> document.formname.myvalue.value= what
> > >> document.formname.submit();
> >>
> >> This doesn't work, too - I'm getting no javascript-error :-(. I don't
> see
> >> any
> >> value in getMyvalue().
> >>
> > >>> dosubmit is a function like
> > >>>
> > >>> <script>
> > >>> dosubmit(what)
> > >>> {
> > >>>       document.formname.value=what;
> > >>>       document.formname.submit();
> > >>> }
> > >>> </script>
> > >>>
> > >>>
> > >>> The browser submits the form (I'm getting no javascript error), but
> I
> > >>> don't get
> > >>> the value of document.formname.value.
> > >>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
I think the reason is that the property is actually on a submit button. And
that does not get submitted as long as the the button is clicked.  Maybe you
could define a hidden variable whose value you can set in the doSubmit
function.

And also, write your anchor tag like this.
<a href="" onclick='doSubmit("value");return false;'>Some Text </a>
The return false is necessary to cancel the default action of the hyperlink.
-- 
Puneet

Re: Submitting forms with javascript in struts [*]

Posted by An...@fiducia.de.
On 9/12/06, puneet.lakhina wrote:
>>On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de> wrote:
>>
>> On 9/12/06, puneet.lakhina wrote:
>>
> >>  On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de>
wrote:
> >>>
> >>>
> >>> Hello,
> >>>
> >>> I do have a problem, because I don't know how to submit a form with
> >>> javascript
> >>> in struts.
> >>>
> >>> Normally, I'm submitting forms like this:
> >>>
> >>> <html:form action="somepath">
> >>> <html:submit property="myvalue" value="send">
> >>> </html:form>
> >>>
> >>> I'm receiving the value with the getter-method getMyvalue() of the
> >>> appropriate
> >>> ActionForm.
> >>>
> >>>
> >>>
> >>> This time, I want to submit the form with a
> >>>
> >>> <a href=javascript:dosubmit("value")>Some text</a>
> >>
>
>
> I think you should be doing it onclick
> <a href="" onclick='doSubmit("value")'>Some Text</a>

Hmm, doesn't work at all. I can't see any value in getMyvalue().

> And could you please make your mail client use Re for reply to a message
> instead of Antwort. Helps in following the thread.

I have to do all the quoting manually, because I hve to use notes, which isn't
able to quote at all as it is usually done in the internet. I'll do my best :-).

>>
>> > Assuming your property name is myvalue
>> > try this is your java script
>> >
> >> document.formname.myvalue.value= what
> >> document.formname.submit();
>>
>> This doesn't work, too - I'm getting no javascript-error :-(. I don't see
>> any
>> value in getMyvalue().
>>
> >>> dosubmit is a function like
> >>>
> >>> <script>
> >>> dosubmit(what)
> >>> {
> >>>       document.formname.value=what;
> >>>       document.formname.submit();
> >>> }
> >>> </script>
> >>>
> >>>
> >>> The browser submits the form (I'm getting no javascript error), but I
> >>> don't get
> >>> the value of document.formname.value.
> >>>


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


Re: Re: Submitting forms with javascript in struts [*]

Posted by Puneet Lakhina <pu...@gmail.com>.
On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de> wrote:
>
> On 9/12/06, puneet.lakhina wrote:
>
> >  On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de>
> wrote:
> >>
> >>
> >> Hello,
> >>
> >> I do have a problem, because I don't know how to submit a form with
> >> javascript
> >> in struts.
> >>
> >> Normally, I'm submitting forms like this:
> >>
> >> <html:form action="somepath">
> >> <html:submit property="myvalue" value="send">
> >> </html:form>
> >>
> >> I'm receiving the value with the getter-method getMyvalue() of the
> >> appropriate
> >> ActionForm.
> >>
> >>
> >>
> >> This time, I want to submit the form with a
> >>
> >> <a href=javascript:dosubmit("value")>Some text</a>
> >


I think you should be doing it onclick
<a href="" onclick='doSubmit("value")'>Some Text</a>

And could you please make your mail client use Re for reply to a message
instead of Antwort. Helps in following the thread.

>
> > Assuming your property name is myvalue
> > try this is your java script
> >
> > document.formname.myvalue.value= what
> > document.formname.submit();
>
> This doesn't work, too - I'm getting no javascript-error :-(. I don't see
> any
> value in getMyvalue().
>
> >> dosubmit is a function like
> >>
> >> <script>
> >> dosubmit(what)
> >> {
> >>       document.formname.value=what;
> >>       document.formname.submit();
> >> }
> >> </script>
> >>
> >>
> >> The browser submits the form (I'm getting no javascript error), but I
> >> don't get
> >> the value of document.formname.value.
> >>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Puneet

Antwort: Re: Submitting forms with javascript in struts [*]

Posted by An...@fiducia.de.
On 9/12/06, puneet.lakhina wrote:

>  On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de> wrote:
>>
>>
>> Hello,
>>
>> I do have a problem, because I don't know how to submit a form with
>> javascript
>> in struts.
>>
>> Normally, I'm submitting forms like this:
>>
>> <html:form action="somepath">
>> <html:submit property="myvalue" value="send">
>> </html:form>
>>
>> I'm receiving the value with the getter-method getMyvalue() of the
>> appropriate
>> ActionForm.
>>
>>
>>
>> This time, I want to submit the form with a
>>
>> <a href=javascript:dosubmit("value")>Some text</a>
>
>
> Assuming your property name is myvalue
> try this is your java script
>
> document.formname.myvalue.value= what
> document.formname.submit();

This doesn't work, too - I'm getting no javascript-error :-(. I don't see any
value in getMyvalue().

>> dosubmit is a function like
>>
>> <script>
>> dosubmit(what)
>> {
>>       document.formname.value=what;
>>       document.formname.submit();
>> }
>> </script>
>>
>>
>> The browser submits the form (I'm getting no javascript error), but I
>> don't get
>> the value of document.formname.value.
>>



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


Re: Submitting forms with javascript in struts

Posted by Puneet Lakhina <pu...@gmail.com>.
On 9/12/06, Andreas.Hartmann@fiducia.de <An...@fiducia.de> wrote:
>
>
> Hello,
>
> I do have a problem, because I don't know how to submit a form with
> javascript
> in struts.
>
> Normally, I'm submitting forms like this:
>
> <html:form action="somepath">
> <html:submit property="myvalue" value="send">
> </html:form>
>
> I'm receiving the value with the getter-method getMyvalue() of the
> appropriate
> ActionForm.
>
>
>
> This time, I want to submit the form with a
>
> <a href=javascript:dosubmit("value")>Some text</a>


 Assuming your property name is myvalue
try this is your java script

document.formname.myvalue.value= what
document.formname.submit();

dosubmit is a function like
>
> <script>
> dosubmit(what)
> {
>       document.formname.value=what;
>       document.formname.submit();
> }
> </script>
>
>
> The browser submits the form (I'm getting no javascript error), but I
> don't get
> the value of document.formname.value.
>
>
> I would be glad to get some help,
> kind regards,
> Andreas Hartmann
>
>
> BTW:
> Is there a way to send another value in the html:submit - button as this,
> which
> is displayed to the user?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Puneet

RE: Submitting forms with javascript in struts

Posted by Raghuveer <ra...@infotechsw.com>.
for "document.formname.value" to be worked you need to use
<html:hidden name="...



-----Original Message-----
From: Andreas.Hartmann@fiducia.de [mailto:Andreas.Hartmann@fiducia.de]
Sent: Tuesday, September 12, 2006 4:50 PM
To: user@struts.apache.org
Subject: Submitting forms with javascript in struts



Hello,

I do have a problem, because I don't know how to submit a form with
javascript
in struts.

Normally, I'm submitting forms like this:

<html:form action="somepath">
<html:submit property="myvalue" value="send">
</html:form>

I'm receiving the value with the getter-method getMyvalue() of the
appropriate
ActionForm.



This time, I want to submit the form with a

<a href=javascript:dosubmit("value")>Some text</a>


dosubmit is a function like

<script>
dosubmit(what)
{
      document.formname.value=what;
      document.formname.submit();
}
</script>


The browser submits the form (I'm getting no javascript error), but I don't
get
the value of document.formname.value.


I would be glad to get some help,
kind regards,
Andreas Hartmann


BTW:
Is there a way to send another value in the html:submit - button as this,
which
is displayed to the user?



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


RE: Submitting forms with javascript in struts

Posted by Ray Madigan <ra...@madigans.org>.
I'm confused here.  Is it your intent to pass a variable 'what' from your
form to the action?

I think the problem is that you need to assign the value what to a hidden
element

<html:hidden property="cpKey"/>

then in your java script assign the value to the value of the hidden element

document.form.cpKey.value = what;

then if your form as the proper setters and getters for cpKey you can get
the value in your action method.

Hope this helps

-----Original Message-----
From: Andreas.Hartmann@fiducia.de [mailto:Andreas.Hartmann@fiducia.de]
Sent: Tuesday, September 12, 2006 4:20 AM
To: user@struts.apache.org
Subject: Submitting forms with javascript in struts



Hello,

I do have a problem, because I don't know how to submit a form with
javascript
in struts.

Normally, I'm submitting forms like this:

<html:form action="somepath">
<html:submit property="myvalue" value="send">
</html:form>

I'm receiving the value with the getter-method getMyvalue() of the
appropriate
ActionForm.



This time, I want to submit the form with a

<a href=javascript:dosubmit("value")>Some text</a>


dosubmit is a function like

<script>
dosubmit(what)
{
      document.formname.value=what;
      document.formname.submit();
}
</script>


The browser submits the form (I'm getting no javascript error), but I don't
get
the value of document.formname.value.


I would be glad to get some help,
kind regards,
Andreas Hartmann


BTW:
Is there a way to send another value in the html:submit - button as this,
which
is displayed to the user?


---------------------------------------------------------------------
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