You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sachin <sa...@paradyne.co.in> on 2004/10/09 17:29:10 UTC
help : submit with javascript problem
hello all ,
i have a struts form and a button outside the form.
on button click , with javascript i need the submit the form
any help is welcome.
My code is like following. but does not work
<html:form action="/something.do">
....
</html:form>
<input type="button" onClick="javascript:callSubmit()">
<script>
function callSubmit() {
document.forms[0].submit();
}
</script>
Sachin Hegde
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by calandraca <ca...@gmail.com>.
Try this:
<html:form action="/something.do" styleId="myFrm">
....
</html:form>
<input type="button" onClick="javascript:callSubmit()">
<script language="javascript">
function callSubmit() {
frm = document.getElementById("myFrm");
frm.submit();
}
</script>
Note that styleId attribute in html:form tag will be rendered as an id
html attribute (see Struts documentation). So you will have a way for
locating the form from javascript since the html node has an
identifier, no matter if the function is called from a button outside
the form. Once into the javascript function you can easily locate the
form and call its submit method. Since you are using DOM
(getElementById), it will run on any standard browser.
On Sat, 9 Oct 2004 20:59:10 +0530, sachin <sa...@paradyne.co.in> wrote:
> hello all ,
>
> i have a struts form and a button outside the form.
> on button click , with javascript i need the submit the form
>
> any help is welcome.
>
> My code is like following. but does not work
>
> <html:form action="/something.do">
> ....
> </html:form>
>
> <input type="button" onClick="javascript:callSubmit()">
>
> <script>
> function callSubmit() {
> document.forms[0].submit();
> }
> </script>
>
> Sachin Hegde
>
> ---------------------------------------------------------------------
> 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: help : submit with javascript problem
Posted by Erik Weber <er...@mindspring.com>.
Sorry, I'm not very good with JavaScript, but could it be that your
function needs a return value? All my JavaScript functions return true
or false, and it seems like I had a problem with a submit function
similar to yours until I put in a return statement.
Erik
sachin wrote:
>hello all ,
>
>i have a struts form and a button outside the form.
>on button click , with javascript i need the submit the form
>
>any help is welcome.
>
>My code is like following. but does not work
>
><html:form action="/something.do">
> ....
></html:form>
>
><input type="button" onClick="javascript:callSubmit()">
>
><script>
>function callSubmit() {
> document.forms[0].submit();
>}
></script>
>
>Sachin Hegde
>
>
>
>
>---------------------------------------------------------------------
>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: help : submit with javascript problem
Posted by Addy Kapur <ad...@gmail.com>.
I am using the following function to dynamically assign the action
name and then submit the form. I am using <html:submit> tag.
function SubmitForm(action){
document.forms[0].userAction.value = action;
document.forms[0].submit();
}
<html:submit value='save' onclick="SubmitForm('save');" />
On Sun, 10 Oct 2004 13:42:21 -0500, Neil Erdwien <ne...@k-state.edu> wrote:
> I think the piece you're missing is that the <input type="button"...>
> tag is only valid inside a FORM element according to the HTML standards.
>
> If I remember correctly from the last time I misplaced the element, the
> browsers differ on their implementation in this case. Mozilla/Firefox
> do the right thing. IE ignores mouse clicks on the button entirely.
>
> I second the removing of the "javascript:". Even if it works, it isn't
> needed.
>
>
>
>
> Erez Efrati wrote:
>
> > I don't see any problem with your code on first sight.
> > Do you have more than one form in the page? Is the page you're trying to
> >
> > Submit is the first one in the page?
> >
> > Try putting the name of the form instead of forms[0].submit do
> > Document.<name-of-your-form>.submit();
> >
> > And also, in your onclick="..." do just onclick="callSumbit();" (remove
> > the 'javascript' token.
> >
> > If it still gives you errors give us the error log so it would be easier
> > to
> > Help you.
> >
> > Hope this helps,
> > Erez
> >
> > -----Original Message-----
> > From: sachin [mailto:sachin.hegde@paradyne.co.in ]
> > Sent: Saturday, October 09, 2004 5:29 PM
> > To: Struts Users Mailing List
> > Subject: help : submit with javascript problem
> >
> > hello all ,
> >
> > i have a struts form and a button outside the form.
> > on button click , with javascript i need the submit the form
> >
> > any help is welcome.
> >
> > My code is like following. but does not work
> >
> > <html:form action="/something.do">
> > ....
> > </html:form>
> >
> > <input type="button" onClick="javascript:callSubmit()">
> >
> > <script>
> > function callSubmit() {
> > document.forms[0].submit();
> > }
> > </script>
> >
> > Sachin Hegde
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
> >
>
> --
> Neil Erdwien, neil@k-state.edu , Web Technologies Manager
> Computing and Network Services, Kansas State University
>
>
>
>
> ---------------------------------------------------------------------
> 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: help : submit with javascript problem
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Geeschhhhh! Wrong again -- I AM. He does have an <input type='button'>
but it is outside the form and used to submit the form. REALLY ODD!
Why is he doing that?
Michael McGrady
Rick Reumann wrote:
>
>> I do wonder in this case, however, whether you use buttons or rely on
>> the auto-gui, why use "button" rather than "submit", if you want to
>> submit? I might also say, that is what submit buttons are for. I
>> assume, however, that there is a reason to use <input type='button'>
>> rather than <input type='submit'> and would like to understand that.
>> I have an old prejudice against JavaScript which may be partly
>> irrational.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Heh, Rick,
I think we both misread what this gentleman is doing. I know I did. I
missed that the button used to submit the form was outside the form.
Why it is outside is not clear. But, he said it was. But, you seem to
have missed that it was being used to submit the form. An odd
situation. The original question, now that I reread it was:
i have a struts form and a button outside the form.
on button click , with javascript i need the submit the form
So, I guess he probably means he has <button> and not <input
type='button'> and you and I have just been jabbering at each other.
LOL Who knows?
Michael McGrady
Rick Reumann wrote:
>
> Actually I'm pretty sure using an html submit button would work as
> well for handling onClick events that don't actually submit a form.
> Using the html button though seems to make sense though just so that
> the page author can see that's it's not actually being used to submit
> a form.
Re: help : submit with javascript problem
Posted by Rick Reumann <st...@reumann.net>.
Michael McGrady wrote the following on 10/10/2004 10:09 PM:
> I do wonder in this case, however, whether you use buttons or rely on
> the auto-gui, why use "button" rather than "submit", if you want to
> submit? I might also say, that is what submit buttons are for. I
> assume, however, that there is a reason to use <input type='button'>
> rather than <input type='submit'> and would like to understand that. I
> have an old prejudice against JavaScript which may be partly
> irrational.
Actually I'm pretty sure using an html submit button would work as well
for handling onClick events that don't actually submit a form. Using the
html button though seems to make sense though just so that the page
author can see that's it's not actually being used to submit a form.
For example on this last application I worked on one of the requirements
was that the client wanted buttons signify something you can 'do' versus
having html links. So for example maybe you were on a page that
displayed a list of employees and next to each employee there would be a
button "edit employee" - this would be a case where we used html buttons
that had an onClick handler that went to a new url. (there were a few
other buttons also on the page). So for example a line might look like...
<c:url var="url" scope="page" value="/editEmployee.do">
<c:param name="dispatch" value="setUp"/>
<c:param name="associateID" value="${associate.associateID}"/>
</c:url>
<input type="button" onClick="goLink('${url}');" value="<fmt:message
key='label.edit'/>
//also may be buttons for "summary" "logs" etc on each row
You really wouldn't want a form to surround the whole employees list
since each button is sumbitting to a totally a different action
You could also use the <button ...> tag. ( I believe you have more html
styling controlling using <button > although I've found <input
type="button" suitable for my needs. )
By the way, a great site for all the HTML and CSS properties:
html http://www.blooberry.com/indexdot/html/tagindex/all.htm
css http://www.blooberry.com/indexdot/css/propindex/all.htm
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Hello, again, Rick,
Thanks for the clarification. Your posts are always enlightening and
informative. I mean that. I am not being sardonic in the slightest.
I have to admit that I don't think they look bad either. However, they
do greatly restrict the GUI team. I like my taste but I know that I do
not have the taste of someone with artistic talent, just like my singing
is rather humdrum. I like my singing too, but no one is going to pay to
hear it for sure. So, I like to have buttons that allow the GUI team to
do their thing. I understand you point on that and have absolutely no
dog in that hunt. I agree that what you do is entirely reasonable.
I do wonder in this case, however, whether you use buttons or rely on
the auto-gui, why use "button" rather than "submit", if you want to
submit? I might also say, that is what submit buttons are for. I
assume, however, that there is a reason to use <input type='button'>
rather than <input type='submit'> and would like to understand that. I
have an old prejudice against JavaScript which may be partly
irrational. I have learned that some things I can only do with
JavaScript. And, that has loosened my prejudice a bit.
Michael McGrady
Rick Reumann wrote:
> I often use the regular html buttons for various things. Users are
> used to seeing these buttons so they know they can click on them. So
> for example someone might have a button "view logs" which doesn't
> necessarily submit a form but opens up a pop up window or maybe goes
> to some other url. Sure you can make images in place of all standard
> html buttons but that that certainly isn't required or necessarily
> even always better. You asked with what seemed like a suprised
> question "Why use an button?" and I'd answer that's what html buttons
> are for - for users to click on. (Actually when you change their
> background color form the default gray, they don't even look that bad
> - although I do realize custom images used as buttons do look the best.)
>
>
> Michael McGrady wrote the following on 10/10/2004 8:56 PM:
>
>> Hi, RIck,
>>
>>
>> I don't understand why this would make someone "make an image look
>> like a form button". I am not sure what that means. All my form
>> buttons are images. They look however I want them to look. I
>> probably don't see what you are saying either. We may be coming from
>> different directions and are passing in the night here.
>>
>>
>> My understanding is that you use an <input type='button'> primarily
>> to do things other than submit. I was not particularly set on <input
>> type='image'>. Why too is he not using <input type='submit'>? I
>> assume there is an answer to this, but I cannot see it in the posts.
>> So, I asked the question.
>>
>> Michael McGrady
>>
>> Rick Reumann wrote:
>>
>>> Michael McGrady wrote the following on 10/10/2004 4:42 PM:
>>>
>>>> Wjau are you using button? Why not use image?
>>>
>>>
>>>
>>>
>>> What's the advantage of using an image in this case? Wouldn't this
>>> require someone to make an image to look like a form button? I'm
>>> probably missing something obvious here:)
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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: help : submit with javascript problem
Posted by Rick Reumann <st...@reumann.net>.
I often use the regular html buttons for various things. Users are used
to seeing these buttons so they know they can click on them. So for
example someone might have a button "view logs" which doesn't
necessarily submit a form but opens up a pop up window or maybe goes to
some other url. Sure you can make images in place of all standard html
buttons but that that certainly isn't required or necessarily even
always better. You asked with what seemed like a suprised question "Why
use an button?" and I'd answer that's what html buttons are for - for
users to click on. (Actually when you change their background color form
the default gray, they don't even look that bad - although I do realize
custom images used as buttons do look the best.)
Michael McGrady wrote the following on 10/10/2004 8:56 PM:
> Hi, RIck,
>
>
> I don't understand why this would make someone "make an image look like
> a form button". I am not sure what that means. All my form buttons are
> images. They look however I want them to look. I probably don't see
> what you are saying either. We may be coming from different directions
> and are passing in the night here.
>
>
> My understanding is that you use an <input type='button'> primarily to
> do things other than submit. I was not particularly set on <input
> type='image'>. Why too is he not using <input type='submit'>? I assume
> there is an answer to this, but I cannot see it in the posts. So, I
> asked the question.
>
> Michael McGrady
>
> Rick Reumann wrote:
>
>> Michael McGrady wrote the following on 10/10/2004 4:42 PM:
>>
>>> Wjau are you using button? Why not use image?
>>
>>
>>
>> What's the advantage of using an image in this case? Wouldn't this
>> require someone to make an image to look like a form button? I'm
>> probably missing something obvious here:)
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Hi, RIck,
I don't understand why this would make someone "make an image look like
a form button". I am not sure what that means. All my form buttons are
images. They look however I want them to look. I probably don't see
what you are saying either. We may be coming from different directions
and are passing in the night here.
My understanding is that you use an <input type='button'> primarily to
do things other than submit. I was not particularly set on <input
type='image'>. Why too is he not using <input type='submit'>? I assume
there is an answer to this, but I cannot see it in the posts. So, I
asked the question.
Michael McGrady
Rick Reumann wrote:
> Michael McGrady wrote the following on 10/10/2004 4:42 PM:
>
>> Wjau are you using button? Why not use image?
>
>
> What's the advantage of using an image in this case? Wouldn't this
> require someone to make an image to look like a form button? I'm
> probably missing something obvious here:)
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Rick Reumann <st...@reumann.net>.
Michael McGrady wrote the following on 10/10/2004 4:42 PM:
> Wjau are you using button? Why not use image?
What's the advantage of using an image in this case? Wouldn't this
require someone to make an image to look like a form button? I'm
probably missing something obvious here:)
--
Rick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Wjau are you using button? Why not use image?
Neil Erdwien wrote:
> I think the piece you're missing is that the <input type="button"...>
> tag is only valid inside a FORM element according to the HTML standards.
>
> If I remember correctly from the last time I misplaced the element,
> the browsers differ on their implementation in this case.
> Mozilla/Firefox do the right thing. IE ignores mouse clicks on the
> button entirely.
>
> I second the removing of the "javascript:". Even if it works, it
> isn't needed.
>
>
> Erez Efrati wrote:
>
>> I don't see any problem with your code on first sight.
>> Do you have more than one form in the page? Is the page you're trying to
>>
>> Submit is the first one in the page?
>>
>> Try putting the name of the form instead of forms[0].submit do
>> Document.<name-of-your-form>.submit();
>>
>> And also, in your onclick="..." do just onclick="callSumbit();" (remove
>> the 'javascript' token.
>>
>> If it still gives you errors give us the error log so it would be easier
>> to Help you.
>>
>> Hope this helps,
>> Erez
>>
>> -----Original Message-----
>> From: sachin [mailto:sachin.hegde@paradyne.co.in] Sent: Saturday,
>> October 09, 2004 5:29 PM
>> To: Struts Users Mailing List
>> Subject: help : submit with javascript problem
>>
>> hello all ,
>> i have a struts form and a button outside the form.
>> on button click , with javascript i need the submit the form
>>
>> any help is welcome.
>>
>> My code is like following. but does not work
>>
>> <html:form action="/something.do">
>> ....
>> </html:form>
>>
>> <input type="button" onClick="javascript:callSubmit()">
>>
>> <script>
>> function callSubmit() {
>> document.forms[0].submit();
>> }
>> </script>
>>
>> Sachin Hegde
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: help : submit with javascript problem
Posted by Neil Erdwien <ne...@k-state.edu>.
I think the piece you're missing is that the <input type="button"...>
tag is only valid inside a FORM element according to the HTML standards.
If I remember correctly from the last time I misplaced the element, the
browsers differ on their implementation in this case. Mozilla/Firefox
do the right thing. IE ignores mouse clicks on the button entirely.
I second the removing of the "javascript:". Even if it works, it isn't
needed.
Erez Efrati wrote:
> I don't see any problem with your code on first sight.
> Do you have more than one form in the page? Is the page you're trying to
>
> Submit is the first one in the page?
>
> Try putting the name of the form instead of forms[0].submit do
> Document.<name-of-your-form>.submit();
>
> And also, in your onclick="..." do just onclick="callSumbit();" (remove
> the 'javascript' token.
>
> If it still gives you errors give us the error log so it would be easier
> to
> Help you.
>
> Hope this helps,
> Erez
>
> -----Original Message-----
> From: sachin [mailto:sachin.hegde@paradyne.co.in]
> Sent: Saturday, October 09, 2004 5:29 PM
> To: Struts Users Mailing List
> Subject: help : submit with javascript problem
>
> hello all ,
>
> i have a struts form and a button outside the form.
> on button click , with javascript i need the submit the form
>
> any help is welcome.
>
> My code is like following. but does not work
>
> <html:form action="/something.do">
> ....
> </html:form>
>
> <input type="button" onClick="javascript:callSubmit()">
>
> <script>
> function callSubmit() {
> document.forms[0].submit();
> }
> </script>
>
> Sachin Hegde
>
>
>
>
> ---------------------------------------------------------------------
> 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
>
--
Neil Erdwien, neil@k-state.edu, Web Technologies Manager
Computing and Network Services, Kansas State University
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: help : submit with javascript problem
Posted by Erez Efrati <er...@netmedia.net.il>.
I don't see any problem with your code on first sight.
Do you have more than one form in the page? Is the page you're trying to
Submit is the first one in the page?
Try putting the name of the form instead of forms[0].submit do
Document.<name-of-your-form>.submit();
And also, in your onclick="..." do just onclick="callSumbit();" (remove
the 'javascript' token.
If it still gives you errors give us the error log so it would be easier
to
Help you.
Hope this helps,
Erez
-----Original Message-----
From: sachin [mailto:sachin.hegde@paradyne.co.in]
Sent: Saturday, October 09, 2004 5:29 PM
To: Struts Users Mailing List
Subject: help : submit with javascript problem
hello all ,
i have a struts form and a button outside the form.
on button click , with javascript i need the submit the form
any help is welcome.
My code is like following. but does not work
<html:form action="/something.do">
....
</html:form>
<input type="button" onClick="javascript:callSubmit()">
<script>
function callSubmit() {
document.forms[0].submit();
}
</script>
Sachin Hegde
---------------------------------------------------------------------
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