[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-23
6
Medium Priority
?
184 Views
Last Modified: 2008-02-01
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";
  //alert("more");
  //CDO_Submit('beSubmit');
  return true;
}
0
Comment
Question by:skellyc
  • 4
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 12655575
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.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12655589
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.

0
 

Author Comment

by:skellyc
ID: 12655778
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Zvonko
ID: 12656039
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.
0
 

Author Comment

by:skellyc
ID: 12656332
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...?
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 12656457
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" />
</form>

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



0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question