Posting a servlet plus several actions with a single click event..

Need to ask another related question;

If I have a click event with the form action <input type = "submit" onClick="doFile(this)" value='upload file'/>

and the following function. How can I add more functionality to this single click event. ie if I wanted to post the servlet then I wanted to go off and create some other stuff, but on the single click action? Is this possible?

function doFile(btn){
  var form1 = btn.form;
  form1.action = "Uploader/uploadfile";
  return true;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
It is possible, but it is not recommanded.
If the same page does two processing jobs, submitting a form and changing the page location, you risk that the server abort the submit request.
ZvonkoSystems architectCommented:
Oh, and the regular way of doing that sequence is to do it in sequence.
That does say: your server side script that takes the submit request creates a response which redirects the user to the new page.

skellycAuthor Commented:
thanks for the info, but thats a bit of a problem. It would be much easier to do a couple of functions on that jsp page. As it is, the servlet will get posted, but then how will the servlet know to get back to the page that initiated it, ann set some conditions for that page?
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ZvonkoSystems architectCommented:
You stated it already: the sequence has to be done on the JavaServerPages script side, not in JavaScript.
The JavaScript is pure browser side client scripting.
skellycAuthor Commented:
sorry, must be a bit thick:) I'm really not following.

The jsp is running on the server, and the servlet being actioned is uploading some files to the unix box. My javascript is running client side methods such as post, close form, disable buttons aka. So, the javascript method runs and sets the action to post to the servlet containing file information required for uploading. This much I'm up to.
But now after the form has been posted and the servlet has run I need to enable/disbale some addiitonal controls on the form using javascript if poss. If inside the servlet what methods can I use to diable/enable controls on the page for example or to run another function?. I assume there must be some kind of mechanism to return to the page and do some more work?
If you have any examples would be great...?
ZvonkoSystems architectCommented:
There is an important part in your description that you did not mention.
It is true that you can do all the form and page control on client side and submit the form data to the server side.
But after the submit you have NO control about the page becuae you cannot know at what time the server received the submitted data and you can change the page.
There is a small trick to circumwent that problem.
You put an invisible IFRAME on your page and submit your form to that IFRAME.
Like this:
<form target="myFrame">
<input type="submit" onClick="doFile(this)" value="upload file" />

<iframe name="myFrame" height="0" width="0"></iframe>

Now you can change the page elements after the form is submitted.
But loading a new page would discard also the hidden iframe and the server would not have a Respons page connection.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.