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
Share on other sites

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>

Link to comment
Share on other sites

Am I missing something or would

<input name="button" type="button" id="button" onclick="document.body.style.backgroundColor = '#'+document.getElementById('cp1_Hex').value" value="Apply Background Color" />

 

Do the trick?

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.