Jump to content

Editing this Javascript so that it adds #


ev5unleash

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>

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.