JavaScript Input Based Background Change? -
my function used work, won't. i'm trying add together if statement when input left blank, returns default background color.
var path = /^([a-fa-f0-9]{6}|[a-fa-f0-9]{3})$/g; function col(obj) { var val = obj.value; if (path.test(val)) { document.body.style.backgroundcolor = '#' + val; } } window.onload = function () { document.getelementbyid('bgcol').onkeyup = function () { col(this); } if (getelementbyid('bgcol'.value = null || ""){ document.body.style.backgroundcolor = '#000000'; } }
//end javascript, begin html below
<input id="bgcol" placeholder="enter hexadecimal color"></input>
you need document.getelementbyid
, clean syntax:
if ( document.getelementbyid('bgcol').value == null || document.getelementbyid('bgcol').value == "")
javascript
No comments:
Post a Comment