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
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"?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.