1.

Solve : user input and background color (html)?

Answer»

hi is there a way of making variables in html and can it have USER input so you type a color in the input box you click ok and the background changes to that color that they just typed into the input box
JavaScript can do it.


<html>
<head>
  <script type="text/javascript">
  function changeBG()
  {
    var bgcolour = document.getElementById('COLOUR').VALUE;
    document.body.style.backgroundColor = bgcolour;
  }
  </script>
</head>

<body>
  <input type="text" id="colour" />
  <input type="submit" value="Change BG" onclick="changeBG()" />
</body>
</html>


The input field will accept common colour names, RGB values, and HEX values. Unfortunately, if the user has JS disabled, then this won't work, but HTML can't do it on its own.



Discussion

No Comment Found