html - Javascript How do i compare two values and then change background color? -
why doesn't code work? want alter color of input background whether value right (green) or not (red).
<html> <head> <script type="text/javascript"> function funct1 () { var username = "63xz4"; if(username == document.getelementbyid('keygen').value ) { document.getelementbyid('keygen').style.backgroundcolor = '#5bc556'; } else { colorchange.style.backgroundcolor = 'red'; } } homecoming 0; </script> </head> <body> <input type="text" id="keygen"> <button onclick="funct1"></button> </body> </html>
<html> <head> <script type="text/javascript"> function funct1 () { var username = "63xz4"; var keygen = document.getelementbyid('keygen'); if(username == keygen.value) { keygen.style.backgroundcolor = '#5bc556'; } else { keygen.style.backgroundcolor = 'red'; } } </script> </head> <body> <input type="text" id="keygen" /> <button onclick="funct1()">button title</button> </body> </html>
the above should help. also, may want this:
give more descriptive names functions declare. save time eliminating calls "getelementbyid" storing dom elements in variables. javascript html
No comments:
Post a Comment