Using "onblur" together with the "onfocus" event - Javascript DOM Event

Javascript examples for DOM Event:onblur

Description

Using "onblur" together with the "onfocus" event

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="myInput" onfocus="focusFunction()" onblur="blurFunction()">

<script>
function focusFunction() {//from  ww w .j a  va2s.c o m
    // Focus = Changes the background color of input to yellow
    document.getElementById("myInput").style.background = "yellow";
}

function blurFunction() {
    // No focus = Changes the background color of input to red
    document.getElementById("myInput").style.background = "red";
}
</script>

</body>
</html>

Related Tutorials