Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

Usually, I use $("#id").val() to return the value of the selected option, but this time it doesn't work. The selected tag has the id aioConceptName

html code

<label>Name</label>

<input type="text" name="name" />

<select id="aioConceptName">

    <option>choose io</option>

    <option>roma</option>

    <option>totti</option>

</select>

1 Answer

0 votes
by (40.7k points)

Try the code given below for dropdown options:

var conceptName = $('#aioConceptName').find(":selected").text();

Here, the val() function doesn't do the trick is because clicking an option doesn't change the value of the dropdown --it is just used to add the: selected property to the selected option which is a child of the dropdown.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...