Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to select option of drop down with Jquery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 347
    Comment on it

    Sometimes we need select option of a drop-down dynamically by clicking on a button or on some other action. We can do this by using "selected" property.

    Example- In the below example I have a drop-down for distance and I want to select option "25 Km" on button click.

    1. <html>
    2. <head>
    3. <title>Demo to show div</title>
    4. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    5. <script type="text/javascript">
    6. function changeValue()
    7. {
    8. $(".radius .option_25").prop("selected","selected");
    9. }
    10. </script>
    11. </head>
    12. <body>
    13. <button type="button" onClick="changeValue();">Change value</button>
    14. <select class="radius">
    15. <option class="option_5" value="5">5 Km</option>
    16. <option class="option_10" value="10">10 Km</option>
    17. <option class="option_15" value="15">15 Km</option>
    18. <option class="option_20" value="20">20 Km</option>
    19. <option class="option_25" value="25">25 Km</option>
    20. <option class="option_30" value="30">30 Km</option>
    21. </select>
    22. </body>
    23. </html>

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: