Jump to content

Recommended Posts

Hey Guys,

 

I'm not that good with JavaScript but I was wondering if someone could help me. I'm using this javascript http://johndyer.name/lab/colorpicker/. I'm trying to use a button to set that color code as the background but it doesn't work because the # is not present. Could someone give me a modified script where it adds the # before the generated color code?

Link to comment
https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/
Share on other sites

I see the input element of the script has an id named "cp1_Hex".

You could just use the getElementById function to get that propery and then add the # char to it

 

<script type="text/javascript">
var color=getElementById("cp1_Hex").innerHTML;
var color="#"+color;
</script>

I'm trying to use a button to set that color code as the background

Well you need some sort of function that handles the onclick of a certain button. What code do you have for that?

It should be something like

<script>
window.load=function(){
    var colorButton=document.getElementById('YOURBUTTONIDHERE');
    colorButton.click=function(){
        //your color changing script here
    }
}
</script>

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.