Rudovich Posted January 26, 2014 Share Posted January 26, 2014 (edited) Hello everyone, I am trying to create a simple slideshow to learn javascript and a small amount of PHP. People are meant to simply upload a photo to their site using for example Filezilla. The website should automaticly take the photo into the slideshow. I am still very novice though. So far I got: + PHP to read the file names in the folder. + Javascript to take over the PHP Array. That is not much.. but I already run into a mistake in the next part. <?php $PhotoSlideAll = scandir('./photos'); $PhotoSlide = array_diff($PhotoSlideAll, array('.', '..'));?> <script> var SlideShow = ["<?php echo join("", "", $PhotoSlide); ?>"]; var SSl=SlideShow.length - 1; var picture = "'../photos/" + SlideShow[0] + "'" document.getElementById("backgroundswitch").style.backgroundImage = "url(picture)";</script> Now somehow, it doesn't actually change the background. Whilst the variable picture is really '../photos/PHOTONAME.jpg' when I use an Alert to test it. Edit: Thank you in advance Edited January 26, 2014 by Rudovich Link to comment Share on other sites More sharing options...
thescientist Posted January 27, 2014 Share Posted January 27, 2014 what is this line supposed to be doing? document.getElementById("backgroundswitch").style.backgroundImage = "url(picture)"; why just set it to picture? you are setting it to a string with the value of url(picture) Link to comment Share on other sites More sharing options...
davej Posted January 27, 2014 Share Posted January 27, 2014 (edited) http://www.w3schools.com/jsref/prop_style_backgroundimage.asp Do you really need to play games escaping the single-quotes? Edited January 27, 2014 by davej Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now