Focus Event using JQUERY

This event is triggered when crusher is placed by using Tab key or mouse is clicked on any object.
$(selector).focus()

  • Video Tutorial on form component events


We can add function to this and execute the code. Let us try to use two input fields for the user. . We will display message asking user to enter name when he keep the focus on first text box, same way we will ask the user to enter email address when the focus is shifted to second text box.

Here is the code …
<script>
$(document).ready(function() {
$('#t1').focus(function(){
$('#d1').html('Enter your name');
});

$('#t2').focus(function(){
$('#d1').html('Enter your email');
});

})
</script>
DEMO of focus Event
In the above demo we have seen how the message is displayed on gaining focus. We can also trigger events when the object lost its focus by using blur() event.

Focus and blur together used to trigger form validation or displaying help message to users.
Event Reference Blur Event

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here .







    Most Popular JQuery Scripts

    1

    Two dependant list boxes

    2

    Calendar with Date Selection

    3

    Data change by Slider

    4

    Show & Hide element


    JQuery Video Tutorials




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer