for (var i = 0; i < input.files.length; ++i) {
name = name.push(input.files[i].name)
}
I want to get the name of the files and put them in a array so I can post them to a php file to upload. Please help.
The variable name is the array I want to post.
is there a loop in javascript like foreach in php
asked Jun 26, 2012 at 8:17
Tharindu Hasthika
571 silver badge9 bronze badges
-
so what's the problem in this?user1432124– user14321242012年06月26日 08:19:17 +00:00Commented Jun 26, 2012 at 8:19
-
What is the question / problem you are having?PeeHaa– PeeHaa2012年06月26日 08:19:43 +00:00Commented Jun 26, 2012 at 8:19
-
i want to upload files using jquery and phpTharindu Hasthika– Tharindu Hasthika2012年06月26日 09:53:27 +00:00Commented Jun 26, 2012 at 9:53
3 Answers 3
How about this:
var name = [];
for (var i = 0; i < input.files.length; ++i) {
name.push(input.files[i].name);
}
answered Jun 26, 2012 at 8:21
Ando
11.5k2 gold badges33 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Tharindu Hasthika
it doesn't give an array after the loop
Ando
name is your array - you add the values inside name and later you can iterate over it.
Try it this way
var name = new Array();
for (var i = 0; i < input.files.length; ++i) {
name[i] = name.push(input.files[i].name)
}
answered Jun 26, 2012 at 8:21
Rafael Marques
8011 gold badge9 silver badges18 bronze badges
1 Comment
RobG
I think you meant
name[i] = inputfiles[i].name;I found the answer the code uses both for loop and jquery $.each loop Thanx
for (var i = 0; i < input.files.length; ++i) {
$.each(input.files.name,function(index,value){
if(index == 'name'){
name.push(value)
}
})
}
answered Jun 27, 2012 at 2:41
Tharindu Hasthika
571 silver badge9 bronze badges
Comments
lang-js