Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a slider that uses an html file in a frame on SharePoint. Slides are changed quite frequently and this slider is being rolled out 10 more times. I am wanting to create a workflow so the end user can change the slider/href themselves. I have created the function below which dynamically creates my "li" and "a" and is working. Eventually I will use variables to get the "src" etc.

My question is I would like to do a "for each" to run through a specified directory and grab the file names so I can create a new "li" and "a" for each file and pull in my "src" for the "a" dynamically also.

If I did not say this correctly I apologize. I am a newbie to JavaScript and programming in general. I have spent quite a bit of time trying to figure this out myself. Any assistance/explanation/direction would be greatly appreciated.

<!DOCTYPE html>
<html>
<head></head>
<body>
    <script>
        document.body.onload = addElement;

        function addElement() {
            //run through a directory and grab URLs

            // create a new li element 
            var newLi = document.createElement("li");
            //create img
            var newImg = document.createElement("img");
            newImg.setAttribute("src", "Intranet_643x296.jpg");
            newImg.setAttribute("height", "100%");
            newImg.setAttribute("border-radius", "10px");
            newImg.setAttribute("alt", "Einstein");
            // Set its contents:
            document.getElementById("ulimage").appendChild(newImg);
        }
    </script>
    <ul id="ulimage"></ul>
</body>
</html>
share|improve this question
    
your question is a statement. my question is, my name is robert. – I wrestled a bear once. yesterday
    
@Iwrestledabearonce. I think although not obvious, his question is pretty obvious. – doz87 yesterday
    
one can obviously sawp "i would like to" with "how do i" but even then the question is unclear. hopefully someone else understood it. – I wrestled a bear once. yesterday

it is not possible ! you can't access client filesystem for obvious security reason.

share|improve this answer
    
sure you can. that's what file inputs are for. – I wrestled a bear once. yesterday
    
you can't access a whole directory via "file" inputs – doz87 yesterday

If you want to do this on the client side unfortunately as @erwan has answered, it isn't possible.

Also, I assume the directory is on the server?
If so then just get all the filenames server side and then you can use them in your javascript.


UPDATE

If you are using php then something like this will grab everything in a specific directory

// Directory 
$directory = $_SERVER['DOCUMENT_ROOT'] . '/images';

chdir($directory); // change directory (not necessary but retrieves only filenames) 

// Get all files in directory
$images = glob('*'); // returns an array that you can use in a foreach loop

// also you should probably lookup the glob function (see below) to see the options

See documentation for glob here Glob
If you want to only select specific extentions then use a pattern

glob('*.{jpg, png}', GLOB_BRACE)

Hope this helps

share|improve this answer
    
It is on the server side. Is there a way to dynamically grab all of them on the server side? They are changed a couple of times a week and I was hoping to have it automated so I would not have to do it for each site. No more than 7-8 slides at one time. – Dan yesterday
    
what language are you using? php? – doz87 yesterday
    
just html and javascript at this point. – Dan 11 hours ago
    
Our corporate office will not enable support for PHP on our farm. Its not clean enough for me to set up a PHP server and have SharePoint serve up the content in a frame. Any other suggestions or solutions? – Dan 10 hours ago
    
Unfortunately you need a server side language to be able to access the file system. HTML and JavaScript won't be able to achieve what you are looking for – doz87 6 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.