Java Script


JavaScript Tutorial


Admission Enquiry Form


How to use color in the textbox to color text?

Example :

<html>
<head>
<title>Kids Programming colour</title>
<link rel="stylesheet" href="style.css">
<style>
div{background-color:lightgrey;}
</style>
<script>
function change_color()
{
var x=document.getElementById("txt_color").value;
document.getElementById("txt").style.color=x;
}
</script>
</head>
<body>
<h2>Q2.Enter a colour in the textbox and change the colour of the text according to the color entered:</h2>

<h1 id="txt">Kids Programming World</h1>
<div>
<label>Enter colour:</label><input type="text" id="txt_color"><br>
<input type="button" value="change color" onclick="change_color()">
<label id="lbl"></label>
<div>
</body>
</html>

Kids Programming colour

Q2.Enter a colour in the textbox and change the colour of the text according to the color entered:

Kids Programming World