Welcome Guest Search | Active Topics | Sign In | Register

Calling javascript BEFORE uploading Options
Michael
Posted: Saturday, January 26, 2008 2:22:37 PM
Rank: Newbie
Groups: Member

Joined: 1/26/2008
Posts: 5
First off... excellent product. I'm becoming a big fan of it!

Second... quick question:

I'm using the AJAXUploader as part of a form. Basically, when I click the upload button, I want to accomplish two things before uploading:

1. Call a javascript that will check to see if the forms are filled out (I know the javscript part)
2. Call a server-side script (asp vb.net) that will check if that file exists already on the server.

If either one raises a flag, I don't want it to upload, rather display an error message.

The question is, how can I call these two things before the actual upload commences?

Thanks!
eo_support
Posted: Saturday, January 26, 2008 7:37:21 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,090
Hi Michael,

I believe it's possible but a bit tricky. The key is to be able to trigger upload through JavaScript. You will need to do:

1. Use LayoutTemplate to customize the upload button and give it "display:none" style attribute. So that the button exists but not visible. Run the page and find out the ID of this button by viewing HTML source. For the purpose of this post, let's say its ID is "original_upload_button_id";
2. Place another button in your form. Handle this form's onclick on client side through JavaScript;
3. Inside your button's onclick handler, perform whatever operations you would like to perform;
4. If everything looks good and you want to continue the upload, call the following code:

Code: JavaScript
var originalUploadButton = 
    document.getElementById("original_upload_button_id");
originalUploadButton.onclick();


That should get you going.

Thanks


Michael
Posted: Saturday, January 26, 2008 7:52:27 PM
Rank: Newbie
Groups: Member

Joined: 1/26/2008
Posts: 5
You're right... a tad tricky... but doable. What about running a server-side script before the upload. Is that possible as well or no? This script will check the database to see if there's a duplicate name or not. I know it could be done after the upload, but why waste the users time when it could be done beforehand.

Thanks!
eo_support
Posted: Saturday, January 26, 2008 8:08:10 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,090
Yes. For that you can use our CallbackPanel to trigger an AJAX callback.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.