Home Tutorial Javascript Javascript change textbox background

 
 

Share on Google+Share on Google+
Javascript change textbox background
Posted on: August 12, 2010 at 12:00 AM
Advertisement
In this section, you will learn how to change the background of textbox.

Javascript change textbox background

In this section, you will learn how to change the background of textbox. Here we have created a textbox and allowed the user to enter the valid name. If the entered name is 'roseindia' then the background changed to green otherwise it will remains red.

Here is the code:

<html>
<
head>
<
title>Change background Color</title>
<
script type="text/javascript">
function check(){
if (document.getElementById('in').value=="roseindia"){
document.getElementById('in').getAttributeNode('class').value="correct";
}else {
document.getElementById('in').getAttributeNode('class').value="incorrect";
}
}
</script>
<
style type="text/css">
.correct {
background: #00ff00;
}
.incorrect
{
background: #f00f00;
}
</style>
</
head>
<
body>
<
p>Enter Valid Name<input id="in" type="text" onkeyup="check();"
class="incorrect" /></p>
</
body>
</
html>

Output:

As the user enters roseindia, backgroud color changed to red.

Advertisement

Related Tags for Javascript change textbox background:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: August 12, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com