Jump to content

Hey..yeah..


Toy

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/213610-heyyeah/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1111852
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1112124
Share on other sites

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>

 

Link to comment
https://forums.phpfreaks.com/topic/213610-heyyeah/#findComment-1112176
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.