javascript - Change the style of an input when submit is pressed -
https://jsfiddle.net/3vz45os8/7/
i've got jsfiddle want change background color of input text in specific color if word type , in 1 if word not type. it's doesn't work got no error in console. if u guys me.
this js function, log every step , didn't error:
function iscorrect() { var test = document.getelementbyid('test').value; if (test.value === "hello") { test.classname = "correct" return true; } else { test.classname = "incorrect" return false; } }
var test = document.getelementbyid('test').value; if (test.value === "hello") {
you're calling .value
twice. take off first line, because otherwise you'll adding classname
(which should camel-cased way) string value instead of input element.
here corrected code , working copy:
function iscorrect() { var test = document.getelementbyid('test'); if (test.value === "hello") { test.classname = "correct"; return true; } else { test.classname = "incorrect"; return false; } }
it's correctly adding class, css being overridden removed default color illustration.
Comments
Post a Comment