How to get the selected value and currently selected text of a dropdown box using jQuery?

<!DOCTYPE html>

<html>

<head>

         <title></title>

         <script

  src="https://code.jquery.com/jquery-3.5.1.slim.min.js"

  integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs="

  crossorigin="anonymous"></script>

</head>

<body>

         <from>

                 <select>

                          <option value="miracle">miracle</option>

                          <option value="caroline">caroline</option>

                 </select>

         </from><br>

         <label></label>

<script type="text/javascript">

         $("select").change(function(){

   var a=$("select").val();

   $("label").text(a);

 

         })

</script>

</body>

</html>


Post a Comment

If you have any doubts, Please let me know
Thanks!

Previous Post Next Post