Javascript Code Change Background Color onkeydown Event

<html>
<head> Javascript Events</head>
<body>
<h2> Enter a number </h2>
<input type="text" id="input1" onkeydown="keydownevent()"/> 
<p id="display">
<script>
<!--
function keydownevent()
{
document.getElementById("input1");
                n=document.getElementById("input1").value;
                document.getElementById("display").style.color="white";  
                switch(Number(n))
                 {
                    case 1: document.getElementById("display").style.background="pink";  
                    document.getElementById("display").innerHTML="pink"; 
                     break
                    case 2: document.getElementById("display").style.background="blue";
                              document.getElementById("display").innerHTML="blue"; 
                     break
                    case 3: document.getElementById("display").style.background="maroon";
                             document.getElementById("display").innerHTML="maroon"; 
                     break
                    case 4:document.getElementById("display").style.background="green";
                       
                        document.getElementById("display").innerHTML="green"; 
                     break;
                   default:  case 4:document.getElementById("display").style.background="orange";
                       
                        document.getElementById("display").innerHTML="orange"; 
                     break;
 
                 
                 }

}
//-->
</script>
</body>
</html>
Output of the Program Code : 
Javascript Events

Enter a number

Comments

Popular posts from this blog

Javascript Code using getElementById and If Else Statement

Javascript Code Using If Else to Compute Discount based on Grades