Search code examples
javascriptcode-generationjscolor

Get color from jscolor


I am using jscolor.js from http://jscolor.com

The function below is what I used before to add the users input to a code generator. They typed in the hex colour of their choice and it would get added to the code generator.

function changeOutlineColour(){
   var jj_input4 = document.getElementById('jj_input4').value;
   document.getElementById('outlinecolour').innerHTML = jj_input4;
   document.getElementById('jj_preview2').style.outlineColor = '#' + jj_input4;
}

This is where the code gets added to, inbetween the span tags

<div class="jj_yourcode">
    <p>#<span id="outlinecolour"></span>;</p>
</div>

Now that I am using jscolor, the hex code doesnt get added the the generator so my question is, what changes do I have to make to the function so that is does?


Solution

  • Figured it out using a button

    HTML:

    <button type="submit" onClick="submitColour()">Set Colour</button>
    

    Javascript:

    function submitColour(){
        var jj_input4 = document.getElementById('jj_input4').value;
        document.getElementById('outlinecolour').innerHTML = jj_input4;
    }