Skip to main content
gamedev.net
🔒 Locked

[web] javascript help

Started by Cygnus_X 1 reply 1k views
Original Post
Cygnus_X
Cygnus_X
I'm writing a web app that makes use of a 3rd party script called SWFUpload. Basically, it allows you to upload multiple files at once (a feature not supported by HTML) and has several nice features. Part of the code I need to modify is the following:

<script type="text/&#106avascript">		var swfu;		window.onload = function () {			swfu = new SWFUpload({				// Backend settings				upload_url: "upload.php",				file_post_name: "resume_file",				// Flash file settings				file_size_limit : "10 MB",				file_types : "*.*",			// or you could use something like: "*.doc;*.wpd;*.pdf",				file_types_description : "All Files",				file_upload_limit : 0,				file_queue_limit : 1,				// Event handler settings				swfupload_loaded_handler : swfUploadLoaded,								file_dialog_start_handler: fileDialogStart,				file_queued_handler : fileQueued,				file_queue_error_handler : fileQueueError,				file_dialog_complete_handler : fileDialogComplete,								//upload_start_handler : uploadStart,	// I could do some client/&#106avascript validation here, but I don't need to.<br>				swfupload_preload_handler : preLoad,<br>				swfupload_load_failed_handler : loadFailed,<br>				upload_progress_handler : uploadProgress,<br>				upload_error_handler : uploadError,<br>				upload_success_handler : uploadSuccess,<br>				upload_complete_handler : uploadComplete,<br><br>				// Button Settings<br>				button_image_url : "XPButtonUploadText_61x22.png",<br>				button_placeholder_id : "spanButtonPlaceholder",<br>				button_width: 61,<br>				button_height: 22,<br>				<br>				// Flash Settings<br>				flash_url : "../swfupload/swfupload.swf",<br>				flash9_url : "../swfupload/swfupload_fp9.swf",<br><br>				custom_settings : {<br>					progress_target : "fsUploadProgress",<br>					upload_successful : false<br>				},<br>				<br>				// Debug settings<br>				debug: false<br>			});<br><br>		};<br>	&lt;/script&gt;<br><br></pre><br><br>Of course, this code will run at window.open and works fine if i install everything from their demo folder.  However, I'd like to add a &lt;form&gt; tag to this page with a &lt;select&gt; box that will update the value of upload_url to something like upload.php?id=1 based &#111;n user input (basically, I want to be able to upload a file to a specific group not into a generic folder, and for this I need some extra information in my upload.php script).  However, I cannot for the life of me figure out how to modify the value of this variable &#111;nce the page has opened.  I've tried adding an &#111;nclick action to the &lt;select&gt; tag that runs the following, but i'm just not that familiar with js.<br><br><pre><br><br>&lt;select id="varvalue" &#111;nmouseup="change_var(swfu)"&gt;<br><br>function chage_var(Var)<br>{<br>   Var.upload_url = "upload.php?id=".document.getElementByID("varvalue").value<br>}<br><br></pre><br><br>But, I'm here because this doesn't work.  Any help would be much appreciated.<br><br><!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - Cygnus_X on June 6, 2010 10:52:09 AM]<!--EDIT--></span><!--/EDIT--></code></pre>
Anntor
Anntor
Quote:
Original post by Cygnus_X
...
swfu = new SWFUpload({... upload_url: "upload.php", ...});...swfu.upload_url = "upload.php?id=".document.getElementByID("varvalue").value...}


This doesn't work, because upload_url is not a member variable of the swfu object. It is a member of the object, which serves the parameter when the swfu object gets initialized.
We can't know how that member is called inside the swfu object without looking at the source code of swfu itself.


But after looking at the source, i found a part with the following swfu methods:
.../* ************************ * Settings methods *   These methods change the SWFUpload settings. *   SWFUpload settings should not be changed directly on the settings object *   since many of the settings need to be passed to Flash in order to take *   effect. * *********************** */...// Public: setUploadUrl changes the upload_url setting.SWFUpload.prototype.setUploadURL = function (url) {...// Public: addPostParam adds post name/value pair.  Each name can have only one value.SWFUpload.prototype.addPostParam = function (name, value) {...

So two methods found, now it's up to you what you want to use. Either setUploadURL to add an additional GET parameter to the request, or addPostParam to add an additional POST parameter to your request. On your server side PHP that would lead to $_GET or $_POST finally.
Cygnus_X
Cygnus_X
Lifesaver.

I'm not 100% complete, but my initial tests show that its working as intended. Also, the syntax swfu.setUpload = function(Var1) was completely new to me, but I figured it out and rather like it (ie, by calling it via swfu.setUpload('myurl.php');). Beautiful.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.