my dog learned polymorphism*
The moose likes Struts and the fly likes submit thru javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "submit thru javascript" Watch "submit thru javascript" New topic
Author

submit thru javascript

manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
When you submit the form thru Java script, will the validation frame work properly.. Any special things, that need to be taken into consideration..
Suppose I have a select one submit button and a oridinary button in my JSP.
With submit button, validation works normally..
for the other button
we write some thing like this..

var form1 = document.abcForm;
form1.action ="XYZAction.do";
form1.submit();
Will the aboove one have the same effect as submit button as far as validation framewok is considered..
}


MT
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
Yeah the validation fwk will still be invoked if you use javascript to submit the form to a struts action.


Adios
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
No Sandy.. No luck.. Its not working for me !! I just called a javscript function, where in i am using same action... but, when i click on 2nd button( a NON-submit button)..
But its not working!!
Any suggestions..
var form1 = document.abcForm;
form1.action ="XYZAction.do";
form1.submit();
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
try document.form1.submit(); in the js function.
Make sure that the name of your action form is the name given to form1 which is the name that appears in the form tag of the source of the page.
It should work. :roll:
You do not have to do this
form1.action ="XYZAction.do";
and even if you want to, the way to do this is form1.action.value = "XYZAction.do";
[ November 21, 2003: Message edited by: sandy gupta ]
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Hi Sandy:
I think that only works for plain html. I had problem with submission some times last year when I successfully developed a demo calling Javascript submit() functions. When I started working on the main project, it did not work. I do not think the javascript submit() function actually submits to the server or the action class.
Unless you have done it sucessfully before then you should let us know how you did it.
Thx,
anselm.
sandy gupta
Ranch Hand

Joined: Jan 30, 2001
Posts: 228
I have done it Anslem and it does work.
function changeCountry()
{
document.RegisterForm.submit();
}
This is my method that i use to submit the form upon the change of the country value in a drop down list.
RegisterForm is the name of my form tag.
This submits the form to a struts url.
What all of us need to understand here is "struts behind the scene is simple old java" struts html tags, still get rendered as html and struts actions still are simple servlets.
Sahil
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
That is nice to know, but I do remember having some problem with this function before. Try it on some other browsers like Mozilla. Not just IE.
manasa teja
Ranch Hand

Joined: May 27, 2002
Posts: 325
Originally posted by Anselm Paulinus:
Hi Sandy:
I do not think the javascript submit() function actually submits to the server or the action class.


I tried that.. no luck again . validation is not getting invoked...
As Anselm says, there is some difference between submitting form with submit button adn submitting thru a javascriipt. I asked similar question
Here also..
May be, i am doing some mistkes here ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: submit thru javascript
 
Similar Threads
validation on submit and not on other page actions?
Struts 1.2
two actionForms for one action class?
How to Skip automatic struts validation if more than 1 submit button present?
textfield event handling