Toy Posted September 16, 2010 Share Posted September 16, 2010 So this is driving me crazy..seriously. I've been googling and trying for days. I'm trying with a "select" box change the background image (no submit button, it'll just reload and change when you click on a option). bg1.png, bg2.png bg3.png And then it'll save the selected background in a cookie so the background you selected will stay even if you browse other pages on the website. That's pretty much it. I would be happy for answers! Quote Link to comment https://forums.phpfreaks.com/topic/213610-heyyeah/ Share on other sites More sharing options...
Miss_Rebelx Posted September 16, 2010 Share Posted September 16, 2010 Uhm... you're trying to do this in HTML? I could be wrong but I think cookies are to be set in PHP or Javascript. (Seeing as someone could have javascript turned off, you'd probably rather PHP) And for an event to fire off of a click, it prefers to happen in Javascript as well. But I believe you could work it out in PHP as well. Either way, you need another language to make this work. For the onChange event for your SELECT tag... try something like: <select onChange="document.body.style.backgroundColor = this.options[this.selectedIndex].value;"> <option value="black">Black</option> <option value="red">Red</option> <option value="green">Green</option> </select> To set the cookie I suggest that your onChange event calls a method... that method sets a cookie either right after changing the background color or after waiting a bit of time, while using Javascript. Someone else might have a more elegant answer. Quote Link to comment https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1111852 Share on other sites More sharing options...
Toy Posted September 17, 2010 Author Share Posted September 17, 2010 Uhm... you're trying to do this in HTML? I could be wrong but I think cookies are to be set in PHP or Javascript. (Seeing as someone could have javascript turned off, you'd probably rather PHP) And for an event to fire off of a click, it prefers to happen in Javascript as well. But I believe you could work it out in PHP as well. Either way, you need another language to make this work. For the onChange event for your SELECT tag... try something like: <select onChange="document.body.style.backgroundColor = this.options[this.selectedIndex].value;"> <option value="black">Black</option> <option value="red">Red</option> <option value="green">Green</option> </select> To set the cookie I suggest that your onChange event calls a method... that method sets a cookie either right after changing the background color or after waiting a bit of time, while using Javascript. Someone else might have a more elegant answer. Haha, sorry! Of curse you have to use other stuff than html. (I wan't to use javascript to do this by the way). I just thought it fit in this section as its mainly html?.. I don't know.. and the code you supplied seems to be for changing the background color? I was more thinking something like.. background image. Quote Link to comment https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1112124 Share on other sites More sharing options...
Miss_Rebelx Posted September 17, 2010 Share Posted September 17, 2010 Ooh right. I read wrong. (Or rather I read what I wanted to read) So I modify my code to this for images instead of colors: <select onChange="document.body.background=this.options[this.selectedIndex].value;"> <option value="image1.ext">image1.ext</option> <option value="image2.ext">image2.ext</option> <option value="image3.ext">image3.ext</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1112176 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.