Write a jQuery code to get the selected value and currently selected text of a dropdown box.

 Write a jQuery code to detect whether the user has pressed 'Enter key' or not

Write a jQuery code to get the selected value and currently selected text of a dropdown box. 

Answer:
File Name : jQuery.html

<html>
<head>
    <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
    <title>SP Creation</title>
</head>
<body>
    <div class="container">
            <div class="col">
                <select name="sel" id="sel" class="form-control">
                    <option value="India">India</option>
                    <option value="US">US</option>
                    <option value="UK">UK</option>
                </select>
            </div>
            <div class="col" id="sel1">
            </div>
    </div>
    <script>
        $(document).ready(function(){
            $("#sel").change(function(){
                var a = $(this).val();
                $("#sel1").html(a);
            });
        });
    </script>
</body>
</html>
Write a jQuery code to get the selected value and currently selected text of a dropdown box. Write a jQuery code to get the selected value and currently selected text of a dropdown box. Reviewed by technical_saurabh on April 30, 2021 Rating: 5

No comments:

Powered by Blogger.