Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the selected text from dropdown using jquery

    • 2
    • 2
    • 0
    • 1
    • 0
    • 0
    • 0
    • 596
    Answer it

    "How to get the selected text from dropdown using jquery"

    While working in Asp.Net Application I got stuck in a following issue.
    This is the code I am using:

    <select class="form-control" id="new-account-prefix" name="newaccountprefix">
                                      <option disabled selected></option>
                                      <option value="mr">Mr.</option>
                                      <option value="ms">Ms.</option>
                                      <option value="mrs">Mrs.</option>
                                      <option value="dr">Dr.</option>
                                  </select>
    

    This is my DropDown, I wan't to get the selected text in my .js file using jquery.
    For Example:
    If the user selects 'Mr.' I wan't the selected value (i.e 'Mr.') using jquery.

    Anybody have some idea, how to acheive this.... Thanks in Advance..!

 1 Answer(s)

  • Hi Mayank,
    You can get the selected text using following syntax.

    $("#yourdropdownid option:selected").text();
    

    Often people confuse between text and val. So the difference is: .text() gives you the selected text what you are seeing on the dropdown. .val() gives you the value part in of the "option" element.

    For Example:- If you write

     $("#new-account-prefix option:selected").text(); 
    

    you will get Mr.,Ms or whatever you select and see in the dropdown
    But if you write

    $("#new-account-prefix option:selected").val(); 
    

    you will get "mr","ms" etc as your result

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: