change bgcolor on user input.


Hellow

So today we are sharing a small program using HTML+CSS+js 
to make a webpage that takes user input to change the background of the webpage.


  • Change background color on User Input using Javascript.



 <html>
     <head>
                <title>change  background color on user input</title>
  <style type="text/css" rel="stylesheet">
   input{
   position:relative;
   top:140px;
   left:200px;
   margin:2px;
   padding:10px;
   height:40px;
   width:400px;
        }
   </style>
            </head>
<body>
      <center>
<div id="change">Enter the color name</div>
               </center>

 <div>
<input type="text" id="col" placeholder="enter color name" oninput="colr();">
     </div>

<script language="javascript">

function colr(){
var getcolor=document.getElementById("col");
document.body.style.backgroundColor=getcolor.value;
                        }
</script>
                </body>
                       </html>





Output:-



You can also use numbers to set background color.


So that's it for today.

thank you.

No comments: