ev5unleash Posted April 20, 2009 Share Posted April 20, 2009 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 More sharing options...
RichardRotterdam Posted April 20, 2009 Share Posted April 20, 2009 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> Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-814296 Share on other sites More sharing options...
ev5unleash Posted April 20, 2009 Author Share Posted April 20, 2009 I've tried adding that to the page, but it still doesn't add # to the textbox. Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-814333 Share on other sites More sharing options...
RichardRotterdam Posted April 20, 2009 Share Posted April 20, 2009 what's the code you have so far? Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-814410 Share on other sites More sharing options...
ev5unleash Posted April 20, 2009 Author Share Posted April 20, 2009 It's the same as that link except I added you're code to my page. Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-814881 Share on other sites More sharing options...
RichardRotterdam Posted April 21, 2009 Share Posted April 21, 2009 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 https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-815253 Share on other sites More sharing options...
ev5unleash Posted April 21, 2009 Author Share Posted April 21, 2009 Yeah, I do it's this <input name="button" type="button" id="button" onclick="document.body.style.backgroundColor = document.getElementById('cp1_Hex').value" value="Apply Background Color" /> Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-815306 Share on other sites More sharing options...
Axeia Posted April 21, 2009 Share Posted April 21, 2009 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 https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-815511 Share on other sites More sharing options...
ev5unleash Posted April 21, 2009 Author Share Posted April 21, 2009 That did it, Thanks! Link to comment https://forums.phpfreaks.com/topic/154808-editing-this-javascript-so-that-it-adds/#findComment-815641 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.