Jump to content

Need help live updating css


wee493

Recommended Posts

I have a site where users can set their own custom css styles. I would like for the page to update live based on the users color selection. For example, if a user selects a color from the color picker for the background then the background color would change to that color. I know this is possiable, it's just that I don't know any javascript just php.

 

Here is what I have

<script type="text/javascript">
function updatebg(){
var myTextField = document.getElementById('branding');
var color =  document.getElementById('input1').value;
myTextField.setAttribute("style", "background-color: ' . color . '");
}
				</script>


<input type="text" name="input1" id="input1" onchange="updatebg()">

 

I've mashed this together after some searching, but it does not work. can anybody help me with this?

Link to comment
https://forums.phpfreaks.com/topic/178102-need-help-live-updating-css/
Share on other sites

Thas for your hel, I got it working using the following code

 

<script>
					function updatebg(){
						var myTextField = document.getElementById('branding');
						var color = document.getElementById('input1').value;
						myTextField.style.backgroundColor = color;
					}
</script>

 

How do I make the thread "Solved"?

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.