Get selected text from a drop-down list select box using jQuery

0 votes

How can I get the selected text (not the selected value) from a drop-down list in jQuery?

May 27, 2022 in Java by Edureka
• 13,690 points
3,210 views

1 answer to this question.

0 votes

Select elements typically have two values that you want to access. First there's the value to be sent to the server, which is easy:

1

2
$( "#myselect" ).val();

// => 1

The second is the text value of the select. For example, using the following select box:

1

2

3

4

5

6

7
<select id="myselect">

<option value="1">Mr</option>

<option value="2">Mrs</option>

<option value="3">Ms</option>

<option value="4">Dr</option>

<option value="5">Prof</option>

</select>

If you wanted to get the string "Mr" if the first option was selected (instead of just "1") you would do that in the following way:

1

2
$( "#myselect option:selected" ).text();

// => "Mr"
answered May 30, 2022 by gaurav
• 23,260 points

Related Questions In Java

0 votes
1 answer

How to get text from text box in Swing?

You can add a Button listener here. ...READ MORE

answered Aug 27, 2019 in Java by Jishan
1,318 views
0 votes
1 answer

How can I read a large text file line by line using Java?

// Open the file FileInputStream file = new ...READ MORE

answered May 2, 2018 in Java by Parth
• 4,640 points
894 views
0 votes
3 answers

Adding text to a file using Java

try { final Path ...READ MORE

answered Sep 6, 2018 in Java by Sushmita
• 6,920 points
1,413 views
0 votes
2 answers

How to get input from user using System.console()?

Scanner in = new Scanner(System.in); int i = ...READ MORE

answered Aug 2, 2018 in Java by Sushmita
• 6,920 points
1,096 views
0 votes
1 answer

How to download and save a file from Internet using Java?

public void saveUrl(final String filename, final String ...READ MORE

answered May 25, 2018 in Java by Rishabh
• 3,620 points
914 views
0 votes
1 answer

Removing an Integer from a List<Integer> in Java

In Java, the method best suiting your argument ...READ MORE

answered Aug 24, 2018 in Java by anonymous
1,579 views
0 votes
2 answers

How do I get distinct element from list in java?

You should use a Set. it doesn't contain duplicates. If ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,188 views
0 votes
1 answer

Using setTimeout to delay timing of jQuery actions

The JavaScript setTimeout () function  is used ...READ MORE

answered May 30, 2022 in Java by gaurav
• 23,260 points
7,982 views
0 votes
1 answer

How to set selected value of jQuery Select2?

The third parameter of the new Option ...READ MORE

answered May 30, 2022 in Java by gaurav
• 23,260 points
40,417 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP