How do we execute a function when an element loses focus?

 Posted by Vivek.Ramapuram on 8/2/2014 | Category: CSS 3 Interview questions | Views: 414 | Points: 40
Answer:

Here on the text box lose focus, we should create onblur event fires and we should execute callfuncton and we should set a background color for text box to highlight
example:

Enter your name: <input type="text" name="txtName" id="txtName" onblur="CallFunction(this.id)" />

<input type="button" id="btn" name="btn" value="Submit" />
<script type="text/javascript">
function CallFunction(id) {
document.getElementById(id).style.background = "blue";
}
</script>


Asked In: While Learning | Alert Moderator 

Comments or Responses

Login to post response