Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 9 February 2015
Keywords : Jquery code,Jquery code for getting selected option as text,How can i get the text value of selected option,Code4beginner

How Can I Get The Text Value Of Selected Option Using JQuery.

JQuery Code For Getting The Text Value Of a Selected Option.

This Jquery Code Getting The Text Value Of a Selected Option. If we select an option and click on 'Get Selected Value' button the selected option is appears as an alert.

Expected Output

Code Snippet


<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>

<body>
    <select id="countries">
        <option value="1">India</option>
        <option value="2">China</option>
        <option value="3">Russia</option>
        <option value="4">Srilanka</option>
        <option value="5">Pakistan</option>
    </select>

    <input type="button" onclick="return getSelected()" value="Get Selected Value" />

    <script type="text/javascript">
    function getSelected() {
        alert($("#countries option:selected").text());
        alert($("#countries").val());
        return false;
    }
    </script>
</body>
</html>

Download Sample Code

Click Right Click here and select "save link as" to download Sample Code. Click here To View sample code working



Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.