Last active
August 29, 2015 14:04
-
-
Save tamizhvendan/7fd57f06e15b77c58d49 to your computer and use it in GitHub Desktop.
DropDownList manipulation using jQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $("#btnIn").click(function () { | |
| $("#countries").val('IN'); | |
| }); | |
| $("#btnEng").click(function () { | |
| $("#countries").val('ENG'); | |
| }); | |
| $("#btnAus").click(function () { | |
| $("#countries").val('AUS'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function () { | |
| function loadDropDownList(collection) { | |
| $.each(collection, function (index, value) { | |
| var listItem = $("<option></option>").val(index).html(value); | |
| $("#countries").append(listItem); | |
| }); | |
| } | |
| var myCollection = {'IN': 'India','AUS': 'Australia','ENG': 'England'}; | |
| loadDropDownList(myCollection); | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function () { | |
| $("#countries").change(function () { | |
| // Place your code here | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Countries: <select id="countries"></select> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function () { | |
| $("#countries").change(function () { | |
| var selectedValue = $("#countries").val(); | |
| $("#countryValue").text(selectedValue); | |
| $("#countryText").text($("#countries > option[value='" + selectedValue + "']").html()); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Selected Country’s Text: <span id="countryText"></span> <br /> | |
| Selected Country’s Value: <span id="countryValue"></span><br /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment