JQuery Forms Select

From CoderLearner
Jump to: navigation, search

Description

$.select() method uses to handle select JavaScript event or trigger event on an element.

Syntax

$.select( [eventData], handler(eventObject) )
$.select();

Example 1

When you select the input text, the $.select() is triggered and display an alert message.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Change</title>
        <script 
            type="text/javascript" 
            src="/lib/jquery-1.7.2.min.js">				 
        </script>

        <script>
            $().ready(function() {
                
                $('#result').select(function(){
                    alert('good old day');
                });
            });
        </script>
    </head>
    <body> 
        <form>
            <input type="text" name="textFirst" id="result" value="Select HERE"/>
        </form>
    </body>
</html>

Try It

Example 2

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Select</title>
        <script 
            type="text/javascript" 
            src="/lib/jquery-1.7.2.min.js">				 
        </script>

        <script>
            $().ready(function() {
               
                $(":input").select( function () { 
                    $("div").text(" selected").show().fadeOut(1000); 
                });

            });
        </script>
    </head>
    <body> 
        <input type="text" value="first name"/>
        <input type="text" value="middle name" />
        <input type="text" value="last name"/>

        <div></div>
    </body>
</html>

Try It