I have a page with two functions. Function A piles an array and displays a button when done. The user clicks the button and the array is passed into Function B... All I have is Function A:
function createUploader(){
var fileArray = new Array();
var i = 0;
var running = 0;
var jList = $( "#list" );
var uploader = new qq.FileUploader({
element: document.getElementById('uploadDiv'),
listElement: document.getElementById('separate-list'),
action: './includes/ajaxUpload/upload.php',
sizeLimit: 10485760,
onSubmit: function(id, fileName){
running++;
},
onComplete: function(id, fileName, responseJSON){
fileArray[i] = fileName;
i++;
running--;
if(running==0){
$('#bineBtn').css("display","");
$.fancybox.resize();
$('#fancybox-content').width(290);
$('#fancybox-wrap').width(310);
$.fancybox.center
$('.qq-upload-button').width(290);
}
}
});
}
Is this even possible? What would be the best way to acplish this?
I have a page with two functions. Function A piles an array and displays a button when done. The user clicks the button and the array is passed into Function B... All I have is Function A:
function createUploader(){
var fileArray = new Array();
var i = 0;
var running = 0;
var jList = $( "#list" );
var uploader = new qq.FileUploader({
element: document.getElementById('uploadDiv'),
listElement: document.getElementById('separate-list'),
action: './includes/ajaxUpload/upload.php',
sizeLimit: 10485760,
onSubmit: function(id, fileName){
running++;
},
onComplete: function(id, fileName, responseJSON){
fileArray[i] = fileName;
i++;
running--;
if(running==0){
$('#bineBtn').css("display","");
$.fancybox.resize();
$('#fancybox-content').width(290);
$('#fancybox-wrap').width(310);
$.fancybox.center
$('.qq-upload-button').width(290);
}
}
});
}
Is this even possible? What would be the best way to acplish this?
Share Improve this question asked Mar 16, 2011 at 16:16 jreed121jreed121 2,0975 gold badges35 silver badges59 bronze badges3 Answers
Reset to default 4Just declare the array outside of the functions, and it can be accessed by them both.
var myarray = [];
function foo(val) {
myarray.push(val);
}
function bar() {
alert (myarray);
}
Further reading: http://www.digital-web./articles/scope_in_javascript/
When creating the button in Function A, could you not do the following:
function function_a()
{
var theArray = [1, 2, 3, 4];
var theButton = $('<button>Click Me</button>');
theButton.click(function() { function_b(theArray) });
}
function function_b(myArray)
{
// Run function code here...
}
You can serialize array to json, save it in value attribute in hidden field, and when button is clicked read hidden field value in function B and deserialize JSON.