Jason28 Posted March 16, 2011 Share Posted March 16, 2011 Hello, I read this in a book and it looked like very simple code. I would like to be enter a hex color in a field like #000000, and have it display that color in a <span> or <div> beside that field automatically. Could you please provide me with a code example that does this? Thanks! Quote Link to comment Share on other sites More sharing options...
nogray Posted March 17, 2011 Share Posted March 17, 2011 You can add an onchange event and set the div background color style to that value e.g. <input type="text" onchange="document.getElementById('my_div_id').style.backgroundColor = this.value;" /><div id="my_div_id"> </div> This code won't validate the user input and an invalid color will cause an error. Quote Link to comment Share on other sites More sharing options...
Jason28 Posted March 17, 2011 Author Share Posted March 17, 2011 Thanks, would it be hard top add an alert error if it is anything but a # and numeric values? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.